标签: r ggplot2 bar-chart categorical-data continuous
我正在尝试使用连续变量和分类变量在ggplot中组合条形图和折线图。我基本上需要做这样的事情:
到目前为止,我已经有了以下代码:
ggplot(data=nutrients, aes(x=Plot, y=Level, fill=Factor)) + geom_bar(stat="identity", position = 'dodge', colour="black")
答案 0 :(得分:1)
ggplot(mtcars, aes(x = factor(cyl), y = wt, fill = factor(gear))) + geom_bar(stat = "identity", position = "dodge") + geom_line(aes(y = ave(wt, cyl, FUN = max), group = gear)) + geom_point(aes(y = ave(wt, cyl, FUN = max), group = gear))
根据需要更改FUN
FUN