这是我的数据:
df <- data.frame(profile = rep(c(1,2), times = 1, each = 3), depth = c(100, 200, 300), value = c(1:3, 2:4))
我计算每个配置文件的深度步骤:
df$diff <- ave(df$depth, df$profile, FUN=function(z) c(z[1], diff(z)))
最后我绘制结果(每个配置文件一个)
对于个人资料1:
ggplot(df, aes(x = factor(profile), y = -diff, fill = value)) + geom_col() +
geom_rect(data = df[which(df$profile == 1),], aes(xmin = profile - 0.5, xmax = profile + 0.5, ymin = -max(df$depth), ymax = 0), size = 0.5, color = "red", fill = NA)
对于个人资料2:
ggplot(df, aes(x = factor(profile), y = -diff, fill = value)) + geom_col() +
geom_rect(data = df[which(df$profile == 2),], aes(xmin = profile - 0.5, xmax = profile + 0.5, ymin = -max(df$depth), ymax = 0), size = 0.5, color = "red", fill = NA)
我得到了这些数字
我的问题我希望在彩条上添加一条代表感兴趣的个人资料最大值的行。所以我希望的情节是那些:
感谢您的帮助