【问题标题】:Plotting two quant columns into one geom_col graph将两个量化列绘制到一个 geom_col 图中
【发布时间】:2019-09-28 11:23:55
【问题描述】:

我正在尝试生成 gapminder 数据的条形图。我需要一张图表,其中 x 轴为大洲,y 轴为 GDP,并且在大陆内,每个最小 GDP 和最大 GDP 都有一个条形图。实在想不通

这是数据集:

continent   min_GDP    max_GDP
Africa      241.1659    21951.21        
America    1201.6372    42951.65        
Asia       331.0000 113523.13       
Europe     973.5332 49357.19        
Oceania    10039.5956   34435.37    

这一直在抛出错误......

ggplot(dataset, aes(continent, min_GDP)) +
geom_bar(position = "dodge") +
ylab("GDP") +
xlab("Year")

【问题讨论】:

    标签: r ggplot2 dplyr


    【解决方案1】:
    library(dplyr)
    library(tidyr)
    library(ggplot2)
    dataset %>%
        gather(var, Dollars, -continent) %>%
        ggplot(aes(x = continent, y = Dollars, fill = var)) +
        geom_col(position = position_dodge())
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-18
      • 1970-01-01
      • 2020-04-21
      • 1970-01-01
      相关资源
      最近更新 更多