如何在ggplot中绘制两个不同的y值?

时间:2018-11-07 19:46:15

标签: r ggplot2

我有一个像这样的数据集

COUNTY == c(COUNTY1, COUNTY2, COUNTY3)
PERC_2012 == c(5%, 6%, 12%)
PERC_2017 == c(55%, 67%, 67%)
data.frame(COUNTY, PERC_2012, PERC2017)

如何绘制x =县和perc 2012和2017的单独行? 谢谢

1 个答案:

答案 0 :(得分:0)

1

您是否正在寻找类似的东西?

代码

ggplot(county) + 
    geom_area(aes(COUNTY, Value, group = PERC, fill = PERC))

数据

COUNTY <- c("COUNTY1", "COUNTY2", "COUNTY3")
PERC_2012 <- c(.05, .06, .12)
PERC_2017 <- c(.55, .67, .67)

county <- data.frame(COUNTY, PERC_2012, PERC_2017)

library(dplyr)
county <- county %>% 
    gather("PERC", "Value", -COUNTY)