我尝试使用以下代码:
library(ggplot2)
library(dplyr)
library(tidyr)
other <- read.table(text='Phase Year V14 V15
Other 2017 0.016488414 0.027183601
Other 2016 0.016937669 0.016937669
Other 2016 0.020214521 0.010313531
Other 2016 0.025205761 0.099279835
Other 2016 0.014341085 0.037596899
Other 2016 0.01622807 0.04254386', header=TRUE)
code <- read.table(text='Phase Year V5 V8 V19 V21
Code 2017 0.016488414 0.053921569 0.01114082 0.027183601
Code 2016 0.033197832 0.016937669 0.016937669 0.016937669', header=TRUE)
test <- read.table(text='Phase Year V6 V11 V20 V22
Test 2017 0.032531194 0.027183601 0.016488414 0.305258467
Test 2016 0.106368564 0.025067751 0.016937669 0.025067751', header=TRUE)
# tidy data
code_df <- code %>%
gather(key, value, V5, V8, V19, V21)
test_df <- test %>%
gather(key, value, V6, V11, V20, V22)
other_df <- other %>%
gather(key, value, V14, V15)
newd <- merge(other_df, code_df, test_df, all=TRUE)
par(mfrow = c(1, 2))
ggplot(data=newd, aes(x=Year)) +
geom_density(aes(group=Phase, color=Phase, fill=Phase, showguide=FALSE)) +
ggtitle("Test")+
xlab("Year")+
ylab("Probability")+
facet_wrap(~Phase, ncol=1)
我的结果看起来并不乐观,我想绘制我的数据集而不会在合并后丢失任何数据集,因为我希望每个数据帧都在一个单独的图形中,但在同一帧中都是相同的。有没有人知道我的代码中出了什么问题?