base = c(1.84,3.92,1.67,1.12,1.63,.62,.59)
e1 = c(.61,1.47,1.68,1.95,1.64,.61,.72)
e2 = c(.64,7.08,1.67,1.12,1.44,.46,.76)
e3 = c(.64,4.47,1.68,2.04,1.45,.4,1.35)
e4 = c(.78,1.61,1.62,1.09,1.46,.66,.76)
e5 = c(.78,.99,1.62,2.32,1.46,.73,.52)
df = data.frame(base,e1,e2,e3,e4,e5)我从一个基线模型和其他5个探索性模型中获得以下参数。我正努力为读者做尽可能多的工作,所以我想做的不仅仅是把它列出来。
是否有一种方法可以用ggplot来表示偏离基线模型的估计值呢?我想不出任何一个,因为有6个值。
谢谢!
发布于 2018-05-07 02:39:30
不知道这是不是你要找的。在这里,我计算了每个模型之间的差异& base模型使用purrr::map_df。之后,我将结果转换为绘制w/ ggplot2的长格式。
library(tidyverse)
base = c(1.84,3.92,1.67,1.12,1.63,.62,.59)
e1 = c(.61,1.47,1.68,1.95,1.64,.61,.72)
e2 = c(.64,7.08,1.67,1.12,1.44,.46,.76)
e3 = c(.64,4.47,1.68,2.04,1.45,.4,1.35)
e4 = c(.78,1.61,1.62,1.09,1.46,.66,.76)
e5 = c(.78,.99,1.62,2.32,1.46,.73,.52)
df = data.frame(base, e1, e2, e3, e4, e5)
# calculate colwise differences
df %>%
map_df( ~ (. - base)) %>%
select(-base) %>%
# create id for each number
mutate(id = row_number()) %>%
# convert to long format
gather(key = "model", value = "diff", -id) -> df_dif
# plot the differences
ggplot(df_dif, aes(x = id, y = diff)) +
geom_col(aes(fill = model), position = "dodge") +
facet_grid(~ model) +
theme_classic()

由reprex封装创建于2018-05-06 (v0.2.0)。
https://stackoverflow.com/questions/50205768
复制相似问题