2016-05-23 145 views
4

我使用点大小可视化变量。 我的问题是,第一个(最小)点大小(在本例中为“70”)显着(不成比例)小于其余部分。 (见CP传说)geom_point最小点大小不成比例

Notice that the point size for "70" is very small

这是我使用的代码:

ggplot(data=testdata, aes(x=variable, y=value, group=ID, size=CP)) + geom_point() 

在这样的数据:

ID CP variable value 
1 C1 70  A 76 
2 C2 95  A 20 
3 C3 100  A 30 
4 C4 NA  A 17 
5 C1 70  B 36 
6 C2 95  B 10 
7 C3 100  B 51 
8 C4 NA  B 41 
9 C1 70  C 89 
10 C2 95  C  1 
11 C3 100  C 94 
12 C4 NA  C  6 
13 C1 70  D 100 
14 C2 95  D 98 
15 C3 100  D 16 
16 C4 NA  D 33 

现在,当我试图调整点大小R不喜欢:

> testplot = ggplot(data=testdata, aes(x=variable, y=value, group=ID, size=CP)) + geom_point() 
> testplot = testplot + scale_size_discrete(range=c(3,5)) 
Warning message: 
Using size for a discrete variable is not advised. 
> testplot 
Error: Continuous value supplied to discrete scale 

而且没有情节产生。同为这样:

> testplot = ggplot(data=testdata, aes(x=variable, y=value, group=ID, size=CP)) + geom_point() 
> testplot = testplot + scale_size_continuous(to=c(3,5)) 
Error in scale_size_continuous(to = c(3, 5)) : 
    unused argument (to = c(3, 5)) 
> testplot 
Error: Continuous value supplied to discrete scale 
+0

一种解决方法:'scale_size(极限= C(1,MAX(TESTDATA $ CP) ,break = unique(testdata $ CP))',但是我不确定为什么默认值不起作用。对于一个连续的'size'变量,你不能使用'discrete'大小刻度,这就是为什么你的'scale_size_discrete ''不能修复 – Gregor

+1

你只是缺少'range'参数而不是'to'参数 - 'scale_size_continuous(range = c(3,5))' – aosmith

+0

感谢@aosmith确实是'scale_size_continuous(range = (3,5 ))'按预期工作。我仍然想知道为什么第一个点的大小非常小,除非我指定的范围等于图例中的步骤。数据的分类性质是否会将其搞乱?我是否必须手动调整每个图形的范围? –

回答

0

原来这是一个,这意味着该点的比例是正确的“人类感知的假象”,但人们可能有印象,事实并非如此。请参阅开发人员的讨论here

对我来说,最好的可能的解决方法是使用scale_radius(range=c(1, 6))

进一步阅读上感知和缩放的关系:Stevens' power law