【问题标题】:R ggplot legend giving decimals when I want whole numbers当我想要整数时,R ggplot图例给出小数
【发布时间】:2015-07-23 18:15:09
【问题描述】:

我正在创建一个气泡图,我的所有值都是整数。但是,当代码运行时,图例比例给了我小数(即 2.5、5、7.5、10)。我希望它是像 2,5,8,11 这样的整数。

这是我的代码:

ggplot() +
geom_path(data = usa, aes(x = long, y = lat, group = group)) + 
theme_general + geom_point(data = CombinedStudentsUSA1, 
aes(x = Long, y = Lat, size = Number), color = "blue", shape=19, alpha=.5)+
scale_size_continuous(range = c(2, 4))

我已经制作了这个图的多个版本,并且所有版本都默认为整数比例。出于某种原因,这个特定版本的数据并没有这样做。帮忙?

【问题讨论】:

  • 指定你喜欢的休息时间?
  • 我不太确定你在问什么。抱歉,我对 R 编码很陌生。这就是我的数据的样子。 X 轴是经度值,y 轴是纬度值,我的 z 轴(组)是人口/组大小。这就是传说所显示的。如果可能的话,我希望图例的值是 2、5、8 和 11。 i62.tinypic.com/2yn1gl5.png
  • scale_size_continuous 提供了一个 breaks 参数,允许您准确指定所需的中断。

标签: r ggplot2 legend


【解决方案1】:

谢谢!那行得通。这是我最终得到的代码:

ggplot() +
geom_path(data = usa, aes(x = long, y = lat, group = group)) + theme_general +
geom_point(data = CombinedStudentsUSA1, aes(x = Long, y = Lat, size = Number),     
color = "blue", shape=19, alpha=.5)+ scale_size_continuous(range = c(2, 4),  
breaks= c(2,4,6,8), name="Number of \nResponses")

http://i57.tinypic.com/291jfcl.jpg

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-01-11
    • 2015-05-23
    • 2013-11-17
    • 1970-01-01
    • 2018-10-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多