【问题标题】:ggplot increase size of pointsggplot 增加点的大小
【发布时间】:2023-02-12 06:00:28
【问题描述】:

我有一个散点图,其中包括不同类型的销售的不同颜色以及基于销售量的不同大小。不过目前点数很少,想增加点数。有没有办法增加图表中的所有点?我尝试添加 scale_size_area(scale = 5) 但点保持相同的大小。

我的代码是这样的

ggplot(abc, aes(x = year, y = amount, color = type, size=amount)) +
  geom_point()+
  guides(color = guide_legend(override.aes = list(size=5)))+
  labs(y= "Amount sold", 
       x = "Year",
       title="",
       fill="Type") +
  scale_size_continuous(name="Size of sales") +
  theme_classic()

我的数据集如下所示:

structure(list(year = c(2009L, 2011L, 2012L, 2012L, 2012L, 2013L, 
2013L, 2014L, 2014L, 2014L, 2014L, 2014L, 2015L, 2015L, 2015L, 
2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2017L, 2017L, 
2017L, 2017L), country = c("Spain", "France", "France", "Italy", 
"Spain", "France", "Spain", "Italy", "France", "Italy", "Italy", 
"Italy", "Spain", "Italy", "Italy", "Spain", "Portugal", "Spain", 
"France", "Spain", "Spain", "Italy", "Portugal", "Italy", "France", 
"Spain"), type = c("Food", "Food", "Food", "Food", "Food", "Food", 
"Food", "Food", "Food", "Metal", "Food", "Food", "Food", "Food", 
"Food", "Cars", "Food", "Cars", "Cars", "Food", "Metal", "Cars", 
"Metal", "Food", "Food", "Cars"), amount = c(0.164692692, 1.47320717, 
2.87002149, 0.040626329, 0.110603352, 0.006904824, 0.123085039, 
0.024957478, 4.1241304, 0.499484718, 0.060575151, 0.171695527, 
2.106156361, 0.915858692, 0.056212947, 1.65235, 1.167061203, 
0.046784638, 0.490756212, 0.328276233, 0.189537764, 0.954012362, 
0.470978739, 0.078503892, 0.253975843, 0.2738115)), class = "data.frame", row.names = c(NA, 
-26L))

非常感谢!

【问题讨论】:

    标签: r ggplot2


    【解决方案1】:

    range= 添加到您的 scale_size_continuous。一个夸张的例子:

    ggplot(abc, aes(x = year, y = amount, color = type, size=amount)) +
      geom_point()+
      guides(color = guide_legend(override.aes = list(size=5)))+
      labs(y= "Amount sold", 
           x = "Year",
           title="",
           fill="Type") +
      scale_size_continuous(name="Size of sales", range=c(2, 20)) +
      theme_classic()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-04-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-10
      • 1970-01-01
      • 2018-11-27
      • 1970-01-01
      相关资源
      最近更新 更多