你还没有真正提供一个可重复的例子,所以我只是用我所拥有的。希望它能做你想要的。可能有更好的方法到达那里,但这就是我所做的:
library(tidyr)
library(ggplot2)
#read the data
df1 <- read.table(text = "
LoopGW NPV Model
1 200 1
2 300 1", stringsAsFactors = FALSE, header = TRUE)
df2 <- read.table(text = "
LoopGW NPVadjusted Model
1 300 3
2 400 3", stringsAsFactors = FALSE, header = TRUE)
#preparing the data.frames for binding so no information gets lost.
d1g <- gather(df1, key = "NPV_flag", value = "NPV", -Model, -LoopGW)
d2g <- gather(df2, key = "NPV_flag", value = "NPVadjusted", -Model, -LoopGW)
#binding the two data.frames
d12g <- rbind(d1g, setNames(d2g, names(d1g)))
#create the groups after which to seperate
d12g$Model_Loop <- paste(d12g$Model, "_", d12g$LoopGW, sep = "")
#Model as factor
d12g$Model <- as.factor(d12g$Model)
#Plot with ggplot
ggplot(d12g, aes(x = Model, y = NPV, group = Model_Loop, color = Model)) + geom_boxplot()
这就是结果。你必须在那里想象 4 个漂亮的箱线图。^^
我希望这就是你想要的。4 个由循环和模型分隔的箱线图?并按型号着色。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句