2013-11-27 68 views
1

我正在绘制一个散点图,其中每个点具有与观察数量相对应的不同尺寸。下面是代码和示例图像输出:在ggplot2散点图中增加可变尺寸点的大小

rm(list = ls()) 

require(ggplot2) 

mydf <- data.frame(x = c(1, 2, 3), 
        y = c(1, 2, 3), 
        count = c(10, 20, 30)) 

ggplot(mydf, aes(x = x, y = y)) + geom_point(aes(size = count)) 
ggsave(file = '2013-11-25.png', height = 5, width = 5) 

enter image description here

这是相当不错的,但有增加所有点的大小的方法吗?特别是,目前它的“10”点太小,因此很难看清楚。

回答

9

用途:

<your ggplot code> + scale_size_continuous(range = c(minSize, maxSize))

其中minSize是您的最低点大小和maxSize是你的最大点大小。

实施例:

ggplot(mydf, aes(x = x, y = y)) + 
    geom_point(aes(size = count)) + 
    scale_size_continuous(range = c(3, 7))