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
• 3,290 points
29 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
• 32,260 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,710 points
104 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,690 points
617 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,710 points
35 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,710 points
875 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
26 views
0 votes
1 answer

How to add external markers in maps?

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

answered Oct 14 in Data Analytics by Cherukuri
• 32,260 points
23 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 in Data Analytics by anonymous
• 32,260 points
68 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
• 32,260 points
19 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 in Data Analytics by anonymous
• 32,260 points
25 views
0 votes
2 answers