# Data:
zz <- "Small Large Lat Long
1 51 2 11 10
2 49 0 12 11
3 77 7 13 13
4 46 5 12 15
5 32 6 13 14
6 54 3 15 17
7 68 0 14 10
8 39 5 12 13"
Data <- as.data.frame(read.table(text=zz,header = TRUE))
我有一个连续变量,比率(大/小),我已经成功绘制了。
尽管在“大”变量中存在一些0。发生这种情况时,我只想绘制“小”数字,因为不可能有比率。为此,我需要执行以下操作:
ratio.both <- Data %>%
filter(Large > 0) %>%
mutate(Ratio = Small/Large)
only.sml<- Data %>%
filter(Large < 1)
然后我将它们都绘制在同一张图上(按较长的数据):
ggplot() +
geom_point(data = ratio.both,aes(x = Long,y = Lat,size = Ratio),stroke = 0,colour = '#3B3B3B',shape=16) +
#
geom_point(data = only.sml,size = Small,shape=1),stroke = 1,shape=1)
注意形状上的差异。这将绘制以下内容
比例(填充)的值和较小值的值之间的差在地图上清晰可见,但在图例中很难。
我想在图例中显示以下内容:
#Title
Size = both.ratio$Ratio,Shape/fill = Ratio or small value #whichever is easier