如何为各种y值绘制带有多个点和线的geom_crossbar

时间:2019-03-27 14:45:35

标签: r ggplot2

我正在尝试为数据中的变量geom_crossbaretgeac图表中添加折线图或点或其他内容。

我当前的代码如下:

library(ggplot2)

df <- data.frame(
    SNL = c("af1","af2","af3","af4","af5","af6"),
    etg = c(1408,1399,1382,1170,1026,869), 
    eac = c(1417,1447,1428,1415,1294,1422),
    prediction = c(1463,1463,1471,1387,1447,1431),
    lower = c(1296,1296,1304,1220,1280,1264),
    upper = c(1631,1631,1638,1554,1614,1598)
)

ggplot(df, aes(x = SNL, y = prediction, ymin = lower, ymax = upper)) + 
    geom_crossbar(aes(color = SNL)) + 
    geom_point(aes(y = etg), shape = 1) + 
    geom_line(aes(y = eac, group = 1))

哪个创建:

Plot

如何为etgeac显示适当的图例?

0 个答案:

没有答案