创建按分类变量分组的连续变量的散点图

时间:2012-12-18 16:11:42

标签: r plot scatter-plot ggplot2

我有一个名为year的分类变量,我想为每个人(类别)绘制,风险值(连续)。我希望每年之间通过线路连接风险。如果我只是简单地在Y轴上绘制风险,然后对变量进行颜色编码就会变得一团糟,因为许多人具有相同的价值或非常相似的东西,你无法看到每个人随时间变化的风险。我已经包含了一个我认为它应该是我在Excel中创建的图像(名称/年份可能不匹配)。我正在为每个人创建一个新的“系列”,问题是我有> 200个人所以不想坐在这里为每个人做这个。
Excelplot

以下是我正在使用的数据示例:

structure(list(IDr = structure(c(2L, 2L, 2L, 2L, 2L, 2L, 1L, 
2L, 1L, 2L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 4L, 4L), .Label = c("F07001_f", 
"F07001_fc", "F07002_f", "F07002_fc", "F07003_fc", "F07004_f", 
"F07005_f", "F07005_fc", "F07006_f", "F07006_fc", "F07008_f", 
"F07009_f", "F07009_fc", "F07010_f", "F07010_fc", "F07011_f", 
"F07011_fc", "F07014_f", "F07014_fc", "F07015_fc", "F07017_fc", 
"F07018_fc", "F07019_f", "F07019_fc", "F07020_f", "F07020_fc", 
"F07021_fc", "F07022_f", "F07023_f", "F07024_fc", "F10001_fc", 
"F10004_fc", "F10008_fc", "F10009_f", "F10009_fc", "F10010_f", 
"F10012_fc", "F10013_fc", "F98015_f", "M07007_m", "M07012_m", 
"M07013_m", "M07016_m", "M10007_m", "M10011_m", "M10015_m"), class = "factor"), 
    ln1wr = c(0.833126490613386, 0.824526258616325, 0.990730077688989, 
    0.981816265754353, 0.933462450382474, 0.932242818088082, 
    0.833865187498825, 0.859381698700969, 0.821716281354653, 
    0.861496579787016, 0.746687947487975, 0.755605414399556, 
    0.689741387425112, 0.694046775802782, 0.746403546860377, 
    0.765095679872529, 1.05733880335233, 1.04549276633745, 0.925765702236673, 
    0.909990929725627), MooseYear = c(2007, 2007, 2008, 2008, 
    2009, 2009, 2010, 2010, 2010, 2010, 7.08, 7.08, 8.09, 8.09, 
    9.1, 9.1, 10.11, 10.11, 2007, 2007)), .Names = c("IDr", "ln1wr", 
"MooseYear"), row.names = c(NA, 20L), class = "data.frame")

我真的不知道从哪里开始,看起来很简单,但我甚至无法在没有将情节变成条形图的情况下获得情节命令。我试过了

plot(ln1wr~ID, data=test)
plot(ln1wr~MooseYear, data=test)
scatterplot(ln1wr~MooseYear, data=test)

他们都没有开始接近起点。我不在乎它是在x轴或y轴上绘制每个人,还是在每个人的箱子上。我只需要了解每个人的风险随时间的变化情况,并观察点之间不断变化的斜率。您会注意到该年内有1个人有多种措施。我有一个额外的分类我可以合并(季节)我正在努力处理。我只是希望它最终会平均或消失。

0 个答案:

没有答案