Add variable size and color of circle marker depending on condition

0 votes
Hey folks!! I'm new to leaflet, Can anyone help me with the below requirement.

Add variable size and color of circle marker depending on condition.

Dataset: Ozone

Condition: I want marker color to be red, green and yellow depending on high, low and medium.

I also want to know condition to apply size of markers depending on similar condiiton.

Thanks,

CJ
Sep 23, 2019 in Data Analytics by anonymous
• 3,450 points
7,460 views

1 answer to this question.

0 votes

Hey,

Give conditions for color or radius within addCircleMarkers as below.

Example -

For variable size

leaflet(df) %>% addTiles() %>%
  addCircleMarkers(
    radius = ~ifelse(field > 50, 6, 10),
  )

For variable color-

Create a function to decide the color

func = colorNumeric(c("green","yellow","red"), domain = NULL)

or

func = colorNumeric(c("green","yellow","red"), domain = NULL,bins = 3)

call the function as below.

leaflet(df) %>% addTiles() %>%
  addCircleMarkers(
    color = func(sort(~field))
  )

Hope it helps!

answered Sep 23, 2019 by Cherukuri
• 33,030 points

Related Questions In Data Analytics

0 votes
4 answers

How to change font size of text and axes on R plots ?

To change the font size of text ...READ MORE

answered Dec 16, 2020 in Data Analytics by Gitika
• 65,770 points
122,285 views
0 votes
1 answer

How to create dummy variables based on a categorical variable of lists in R?

You can use mtabulate in the following way: library(qdapTools) cbind(data[1], ...READ MORE

answered Apr 13, 2018 in Data Analytics by CodingByHeart77
• 3,750 points
2,623 views
0 votes
1 answer

How can I print string and variable contents on the same line using R?

There are two options for doing so.  You ...READ MORE

answered May 9, 2018 in Data Analytics by zombie
• 3,790 points
1,877 views
0 votes
1 answer

How can I change font size and direction of axes text in ggplot2 ?

You can try theme(): Library(ggplot2) a <- data.frame(x=gl(10, 1, ...READ MORE

answered May 30, 2018 in Data Analytics by zombie
• 3,790 points
4,341 views
0 votes
1 answer

plot map points from a dataframe

Hi Peter, Use below code. leaflet(df) %>% addTiles() %>% ...READ MORE

answered Sep 17, 2019 in Data Analytics by priya
921 views
0 votes
1 answer

How to add external markers in maps?

Use external markers by creating icons using ...READ MORE

answered Oct 14, 2019 in Data Analytics by Cherukuri
• 33,030 points
906 views
0 votes
1 answer

How to add legend or any text on the map in leaflet?

See below example, > p = colorFactor(palette = ...READ MORE

answered Oct 28, 2019 in Data Analytics by anonymous
• 33,030 points
8,909 views
0 votes
0 answers

fix the map area using leaflet and use ggplot

I created a map using leaflet and ...READ MORE

Sep 18, 2019 in Data Analytics by anonymous
• 33,030 points
664 views
0 votes
1 answer

How to provide color to ggplot scatter chart depending on field value?

cyl is a continuous value field, so ...READ MORE

answered Nov 2, 2019 in Data Analytics by anonymous
• 33,030 points
822 views
+1 vote
3 answers

How to change the value of a variable using R programming in a data frame?

Try this: df$symbol <- as.character(df$symbol) df$symbol[df$sym ...READ MORE

answered Jan 11, 2019 in Data Analytics by Tyrion anex
• 8,700 points
35,823 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP