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 in Data Analytics by anonymous
• 1,470 points
10 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 by Cherukuri
• 26,880 points

Related Questions In Data Analytics

0 votes
1 answer

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

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

answered Apr 20, 2018 in Data Analytics by zombie
• 3,690 points
72 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,680 points
536 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,690 points
29 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,690 points
526 views
0 votes
1 answer

plot map points from a dataframe

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

answered Sep 17 in Data Analytics by priya
14 views
0 votes
0 answers

How to add external markers in maps?

How to add external markers in maps? READ MORE

Sep 17 in Data Analytics by ruchitha
13 views
0 votes
0 answers

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

I'm new to leaflet and working on ...READ MORE

Sep 18 in Data Analytics by anonymous
• 26,880 points
17 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 in Data Analytics by anonymous
• 26,880 points
9 views
0 votes
2 answers
0 votes
1 answer

Rmarkdown color to inline and block text

Hey, To mark text as inline, use a ...READ MORE

answered Sep 17 in Data Analytics by anonymous
• 26,880 points
19 views