【发布时间】:2016-06-10 17:03:23
【问题描述】:
我有一个关于 R 中使用 ggplot2 的直方图的问题。我一直在努力从两个不同的变量中表示直方图中的一些值。在尝试并在 Stackoverflow 中寻找一些解决方案后,我得到了它,但是......有人知道如何打印 NA 算作一个新列来比较两个变量中的缺失吗?
这里是 R 代码:
i<-"ADL_1_bathing"
j<-"ADL_1_T2_bathing"
t1<-data.frame(datosMedicos[,i])
colnames(t1)<-"datos"
t2<-data.frame(datosMedicos[,j])
colnames(t2)<-"datos"
t1$time<-"t1"
t2$time<-"t2"
juntarParaGrafico<-rbind(t1,t2)
ggplot(juntarParaGrafico, aes(datos, fill = time) ) +
geom_histogram(col="darkblue",alpha = 0.5, aes(y = ..count..), binwidth = 0.2, position = 'dodge', na.rm = F) +
theme(legend.justification = c(1, 1), legend.position=c(1, 1))+
labs(title=paste0("Distribution of ",i), x=i, y="Count")
这是输出:
关于两个变量值但没有缺失条的图像:
【问题讨论】: