【问题标题】:Changing the range of sizes used in a bubble plot更改气泡图中使用的大小范围
【发布时间】:2012-07-19 23:32:20
【问题描述】:

我正在使用 R 来创建我正在研究的行业中战略组的竞争地图。网点数量沿着 x 轴,销售额是 y 轴以及气泡的大小。使用的代码:

qplot(data = supermarket, x = outlets, y = sales, size = sales, color = retailer)   

但是,我需要增加气泡的整体大小,因为目前还不清楚。请参阅下面的示例。

我需要的是让气泡保持相对于销售额的大小,但总体上要变大以提高可见度。

【问题讨论】:

  • @bdemarest,刚刚注意到你在这里击败了我的答案。几天前我自己也有同样的问题。
  • 以上链接已失效。

标签: r charts ggplot2


【解决方案1】:

玩:+ scale_size_continuous(range = c()),如:

#set.seed(10)
#supermarket <- data.frame(sales = sample(1:50000, 12), 
#    outlets = sample(1:3000, 12), retailer = LETTERS[1:12])

#I use ggplot rather than qplot and understand it so that's what I used here
ggplot(data = supermarket, aes(x=outlets, y=sales, size=sales, color=retailer)) + 
            geom_point() + scale_size_continuous(range = c(3, 8))

或者您也可以使用您的代码并添加 scale_size_continuous,就像上面 bdemarest 建议的那样:

qplot(data = supermarket, x = outlets, y = sales, size = sales, color = retailer) + 
    scale_size_continuous(range = c(3, 8))

两者都会产生相同的结果。

【讨论】:

  • 太棒了。非常感谢,这几乎是完美的。但是,如果我想将 LETTERS 更改为列名(超市的名称),我应该使用哪个命令?
  • 使用您的数据。它们只是字母,因为我编造了数据。
  • 谢谢。但是我应该使用哪个“代码”(对象?)而不是字母?
  • 通过查看您的代码,您有 3 列:salesoutletsretailer。使用那些。实际上,您可以忽略我的代码的第一部分,因为您已经在数据框中拥有它(我会将其变灰)未来有类似问题的搜索者。
猜你喜欢
  • 2015-08-23
  • 2015-05-10
  • 2011-12-23
  • 2016-12-01
  • 1970-01-01
  • 2018-06-13
  • 2016-07-31
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多