本文介绍了改变气球图中点的大小并保持零值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
对于这些数据 Data< - structure(list(ObsVal = c(22L,50L,8L,15L, 54L,30L,11L,90L,
6L,53L,9L,42L,72L,40L,60L,58L,1L,20L,37L,2L,50L,
68L,20L,19L,58L, 5L),Porp = c(0.0909090909090909,0.02,0,
0,0,0,0.2272727272727273,0.455555555555556,0,0.452830188679245,
0.111111111111111,0.404761904761905,0,0.025,0.0166666666666667,0
0.120689655172414 ,0,0.1,0.108108108108108,0,0,0.0294117647058824,
0,0,0.310344827586207,0),Pred = c(26,52,6,15,39,30,
13,85, 8,62,5,48,92,52,71,68,1,28,47,1,41,106,
29,19,39,7)),.Names = c(ObsVal ,Porp,Pred),class =data.frame,row.names = c(NA,
-26L))
和这段代码
require(ggplot2)
p< - ggplot(data,aes(x = ObsVal,y = Pred,size = Porp))+
geom_point()+
geom_smooth(method = lm,color =red)+
theme_bw()+
指南(大小= FA LSE)
p
我可以制作这张图
但点数太小。当我通过代码增加尺寸时,可以使用
p + scale_size_area(max_size = 10)
圆点变大,但是我忽略了Porp为零的值。
我试着加1到所有Porp值,但大小都是一样的。
可以像第二张图一样增加点的大小,但也包括点数Porp为零?
解决方案
您可以尝试使用 scale_size_continuous
及其范围
参数。例如。像这样:
p + scale_size_continuous(range = c(2,10))
With these data
Data <- structure(list(ObsVal = c(22L, 50L, 8L, 15L, 54L, 30L, 11L, 90L,
6L, 53L, 9L, 42L, 72L, 40L, 60L, 58L, 1L, 20L, 37L, 2L, 50L,
68L, 20L, 19L, 58L, 5L), Porp = c(0.0909090909090909, 0.02, 0,
0, 0, 0, 0.272727272727273, 0.455555555555556, 0, 0.452830188679245,
0.111111111111111, 0.404761904761905, 0, 0.025, 0.0166666666666667,
0.120689655172414, 0, 0.1, 0.108108108108108, 0, 0, 0.0294117647058824,
0, 0, 0.310344827586207, 0), Pred = c(26, 52, 6, 15, 39, 30,
13, 85, 8, 62, 5, 48, 92, 52, 71, 68, 1, 28, 47, 1, 41, 106,
29, 19, 39, 7)), .Names = c("ObsVal", "Porp", "Pred"), class = "data.frame", row.names = c(NA,
-26L))
and this code
require(ggplot2)
p <- ggplot(Data, aes(x=ObsVal, y=Pred, size=Porp))+
geom_point()+
geom_smooth(method=lm, color="red")+
theme_bw()+
guides(size=FALSE)
p
I can make this plot
but the dots are too small. When I increase the size with the code
p+scale_size_area(max_size=10)
The dots get larger, but I loose the values where Porp is zero.
I tried to add 1 to all Porp values, but then the sizes were all the same.
It is possible to increase the size of the dots as in the 2nd fig, but also include points were Porp is zero?
解决方案
You may try to use scale_size_continuous
and its range
argument. E.g. something like this:
p + scale_size_continuous(range = c(2, 10))
这篇关于改变气球图中点的大小并保持零值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!