【发布时间】:2019-10-19 11:04:26
【问题描述】:
我对 R 比较陌生,每当我尝试在我的点图中添加月份和年份时都会遇到问题。当我使用 lattice 运行数据时,我会这样做:
require(lattice)
data_conrad = read.csv("/Users/Danniel/Desktop/conrad_made_up.csv", header = TRUE)
data_conrad
lattice::dotplot(data_conrad$Patient ~ data_conrad$Value | data_conrad$Year,
data=data_conrad, xlab="Time", ylab="Patient", scales= list(x = list(at = seq(from = 1, to = 12, by =1))))
但是,我试图获取实际月份而不是 (1,2,3,4...12),并且我试图用实际年份 (2010, 2011, 2012) 替换 "Data_Conrad$Year" ),但是我遇到了问题。
输入dput(data_conrad) 后,R 的输出如下:
structure(list(Patient = structure(c(1L, 2L, 3L, 4L, 5L, 6L,
7L, 8L, 9L, 10L, 1L, 2L, 3L, 4L, 5L, 6L, 8L, 9L, 10L, 1L, 6L,
8L), .Label = c(" 1", " 2", " 3", " 4", " 5", " 6", " 7", " 8",
" 9", "10"), class = "factor"), Month = structure(c(5L, 4L, 6L,
8L, 1L, 3L, 2L, 2L, 4L, 10L, 1L, 7L, 11L, 10L, 9L, 10L, 10L,
3L, 5L, 6L, 3L, 5L), .Label = c("Apr", "Aug", "Dec", "Feb", "Jan",
"Jul", "Jun", "Mar", "May", "Nov", "Sep"), class = "factor"),
Year = structure(c(1L, 2L, 3L, 1L, 3L, 2L, 1L, 1L, 3L, 2L,
2L, 2L, 3L, 1L, 3L, 3L, 1L, 3L, 3L, 3L, 3L, 3L), .Label = c("2010",
"2011", "2012"), class = "factor"), Value = structure(c(1L,
2L, 7L, 3L, 4L, 11L, 8L, 8L, 2L, 10L, 4L, 6L, 9L, 10L, 5L,
10L, 10L, 11L, 1L, 7L, 11L, 1L), .Label = c(" 1", " 2", " 3",
" 4", " 5", " 6", " 7", " 8", " 9", "11", "12"), class = "factor")), class = "data.frame", row.names = c(NA,
-22L))
非常感谢您的帮助!
【问题讨论】:
-
我对@987654326@ 不太熟悉,但如果您提供示例数据来使用它可能会有所帮助。它可以来自
dput(head(data_conrad))或以编程方式构建,例如data.frame(Year = ..., ...)。 -
绝对!我刚刚使用 'dput(data_conrad)' 编辑了帖子,非常感谢!