Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
143 views
in Technique[技术] by (71.8m points)

r - Understand scale_gradient scaling

stat_density2d(aes(fill = ..level..), alpha = .5, h = .02, n = 300, 
   geom = "polygon", data = accident_before) + 
scale_fill_gradient(low = "green", high = "red", guide = "colorbar", 
  name = "Level", breaks=seq(-40,80,30), limits=c(-40,80)) 

This is the code I am using but the output of this is a map that plots the city in grey color. What do low and high specify here? How should I understand which dataset is considered to output the map in what color.

question from:https://stackoverflow.com/questions/65840202/understand-scale-gradient-scaling

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

you are setting your scale limits to be -40 to 80, thus those will be the high and low colors. If you have grey values, this is either because you have NA values, or you have values out of this range.

Check ?ggplot2::scale_fill_gradient for a bit more information.

The underlying gradient is calculated with scales::seq_gradient_pal()


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...