由于我是R的初学者,我允许我自己问R用户一个小问题。我想用图形(点,线,曲线)表示两组人的体重,用药物(0,1)治疗和未用药治疗10次(月)。
drug NumberIndividu Mar Apr May June July August September November October December
1 9 25.92 24.6 31.85 38.50 53.70 53.05 65.65 71.45 69.10 67.20
1 10 28.10 26.6 32.00 38.35 53.60 53.25 65.35 65.95 67.80 65.95
1 11 29.10 28.8 30.80 38.10 52.25 47.30 62.20 68.05 66.20 67.55
1 13 27.16 25.0 27.15 34.85 47.30 43.85 54.65 62.25 60.85 58.05
0 5 25.89 25.2 26.50 27.45 37.05 38.95 43.30 50.60 48.20 50.10
0 6 28.19 27.6 28.05 28.60 36.15 37.20 40.40 47.80 45.25 44.85
0 7 28.06 27.2 27.45 28.85 39.20 41.80 51.40 57.10 54.55 55.30
0 8 22.39 21.2 30.10 30.90 42.95 46.30 48.15 54.85 53.35 49.90我试过了:
w= read.csv (file="/file-weight.csv", header=TRUE, sep=",")
w<-data.frame(w)
rownames(w[1:8,])
rownames(w)<-(c(w[,1]))
cols <- character(nrow(w))
cols[rownames(w) %in% c(rownames(w[1:4,]))]<-"blue"
cols[rownames(w) %in% c(rownames(w[5:8,]))]<-"red"
pairs(w,col=cols)我的问题是如何配置matplot函数以拥有一个图形视图(点或曲线或hist +曲线)我的主要目标是可视化一个图像中所有日期的第一列(药物)的两种颜色下的所有个体分布。
非常感谢您的建议
发布于 2014-01-15 01:42:45
这就是你所想的吗?

代码基于对->this question<-的回答,只是使用您的数据集(df)而不是iris。因此,在响应中,替换为:
x <- with(iris, data.table(id=1:nrow(iris), group=Species, Sepal.Length, Sepal.Width,Petal.Length, Petal.Width))通过以下方式:
xx <- with(df, data.table(id=1:nrow(df), group=drug, df[3:12]))如果你想要的只是密度图/直方图,那就更容易了(见下文)。这些都是互补的,因为它们表明控制组和测试组的体重都在增加,只是在测试组中增加得更快。你不会从散点图矩阵中提取出来的。此外,还有一种迹象表明,控制组的体重变异性更大,并随着时间的推移而增长。
library(ggplot2)
library(reshape2) # for melt(...)
# convert df into a form suitable to use with ggplot
gg <- melt(df,id=1:2, variable.name="Month", value.name="Weight")
# density plots
ggplot(gg) +
stat_density(aes(x=Weight, y=..scaled.., color=factor(drug)),geom="line", position="dodge")+
facet_grid(Month~.)+
scale_color_discrete("Drug")
# histograms
ggplot(gg) +
geom_histogram(aes(x=Weight, fill=factor(drug)), position="dodge")+
facet_grid(Month~.)+
scale_fill_discrete("Drug")


https://stackoverflow.com/questions/21119791
复制相似问题