【发布时间】:2018-05-12 16:43:36
【问题描述】:
我有这些数据:
# R> smokeyes_male
LungCap.cc. Age..years. Height.inches. Smoke Gender Caesarean
211 6.575 10 63.2 yes male yes
220 7.000 10 62.8 yes male yes
252 9.350 11 71.2 yes male no
258 7.925 11 67.1 yes male no
280 10.275 11 72.2 yes male no
285 8.925 11 65.6 yes male yes
305 6.450 12 61.0 yes male yes
345 8.000 12 64.5 yes male no
370 9.750 13 72.8 yes male no
371 8.025 13 66.2 yes male no
我需要根据人的身高或是否剖腹产绘制肺活量和年龄之间的关系。
我收到以下错误:
library(ggplot2)
smoker_male_graph=ggplot(smokeyes_male,aes(x=smokeyes_male$age,y=smokeyes_male$LungCap.cc.)) + geom_point()
smoker_male_graph + facet_wrap(~smokeyes_male$Height.inches.)
错误:美学必须是长度1或与数据相同(33):x,y
代码如下:
smokeyes_male <- structure(list(LungCap.cc. = c(6.575, 7, 9.35, 7.925, 10.275,
8.925, 6.45, 8, 9.75, 8.025), Age..years. = c(10L, 10L, 11L,
11L, 11L, 11L, 12L, 12L, 13L, 13L), Height.inches. = c(63.2,
62.8, 71.2, 67.1, 72.2, 65.6, 61, 64.5, 72.8, 66.2), Smoke = structure(c(1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = "yes", class = "factor"),
Gender = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L), .Label = "male", class = "factor"), Caesarean = structure(c(2L,
2L, 1L, 1L, 1L, 2L, 2L, 1L, 1L, 1L), .Label = c("no", "yes"
), class = "factor")), .Names = c("LungCap.cc.", "Age..years.",
"Height.inches.", "Smoke", "Gender", "Caesarean"), class = "data.frame", row.names = c("211",
"220", "252", "258", "280", "285", "305", "345", "370", "371"
))
【问题讨论】:
-
根据你的例子,它应该是
smokeyes_male$Age..years.而不是smokeyes_male$age,第一个对我来说很好。并且不需要每次都使用smokeyes_male$,只需使用变量名
标签: r ggplot2 facet-grid