如何在 R 中制作剖面图?
How to make profile plot in R?
数据集以长格式布局,有一些缺失值,有 4 列,
第一列是“id”,
第二列是二进制变量“条件”,
第三列是变量“时间”,
第 4 个变量是“结果,
现在,我想用R创建一个剖面图,它显示在附件中的SPSS中。我知道如何使用SPSS创建它,但我不知道如何在R中执行此操作。(显示SPSS创建的图片的链接列在最后post)
原始数据集结构如下,
df <- structure(list(id = structure(c(101, 101, 101, 101, 101, 102,
102, 102, 102, 102, 103, 103, 103, 103, 103, 104, 104, 104, 104,
104, 105, 105, 105, 105, 105, 106, 106, 106, 106, 106, 107, 107,
107, 107, 107, 108, 108, 108, 108, 108, 109, 109, 109, 109, 109,
110, 110, 110, 110, 110, 111, 111, 111, 111, 111, 112, 112, 112,
112, 112, 113, 113, 113, 113, 113, 114, 114, 114, 114, 114, 115,
115, 115, 115, 115, 116, 116, 116, 116, 116, 117, 117, 117, 117,
117, 118, 118, 118, 118, 118, 119, 119, 119, 119, 119, 120, 120,
120, 120, 120, 121, 121, 121, 121, 121, 122, 122, 122, 122, 122,
123, 123, 123, 123, 123, 124, 124, 124, 124, 124, 126, 126, 126,
126, 126, 127, 127, 127, 127, 127, 129, 129, 129, 129, 129, 130,
130, 130, 130, 130, 131, 131, 131, 131, 131, 132, 132, 132, 132,
132, 133, 133, 133, 133, 133, 134, 134, 134, 134, 134, 135, 135,
135, 135, 135, 136, 136, 136, 136, 136, 137, 137, 137, 137, 137,
138, 138, 138, 138, 138, 139, 139, 139, 139, 139, 140, 140, 140,
140, 140, 201, 201, 201, 201, 201, 202, 202, 202, 202, 202, 203,
203, 203, 203, 203, 204, 204, 204, 204, 204, 205, 205, 205, 205,
205, 206, 206, 206, 206, 206, 207, 207, 207, 207, 207, 208, 208,
208, 208, 208, 210, 210, 210, 210, 210, 211, 211, 211, 211, 211,
212, 212, 212, 212, 212, 213, 213, 213, 213, 213, 214, 214, 214,
214, 214, 215, 215, 215, 215, 215, 216, 216, 216, 216, 216, 217,
217, 217, 217, 217, 218, 218, 218, 218, 218, 219, 219, 219, 219,
219, 220, 220, 220, 220, 220, 301, 301, 301, 301, 301, 302, 302,
302, 302, 302, 303, 303, 303, 303, 303, 304, 304, 304, 304, 304,
305, 305, 305, 305, 305), label = "Subject #", format.spss = "F11.0", display_width = 11L),
condition = structure(c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0,
0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0,
0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0,
1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1,
1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0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format.spss = "F4.0"),
outcome = structure(c(3.09104245335832, 2.89037175789616,
2.07944154167984, 2.30258509299405, 2.63905732961526, 3.58351893845611,
2.94443897916644, 2.19722457733622, 2.83321334405622, 2.99573227355399,
3.13549421592915, 2.89037175789616, 2.99573227355399, 2.70805020110221,
2.30258509299405, 3.43398720448515, 3.04452243772342, 2.56494935746154,
2.484906649788, 1.38629436111989, 3.25809653802148, 2.83321334405622,
2.484906649788, 2.56494935746154, 2.77258872223978, 3.55534806148941,
2.484906649788, 2.70805020110221, 1.38629436111989, 2.63905732961526,
3.49650756146648, 3.04452243772342, 2.70805020110221, 2.56494935746154,
2.484906649788, 3.2188758248682, 3.2188758248682, 3.09104245335832,
3.09104245335832, 3.09104245335832, 3.17805383034795, 3.17805383034795,
2.56494935746154, 2.30258509299405, 1.38629436111989, 3.13549421592915,
2.77258872223978, 2.77258872223978, NA, NA, 3.17805383034795,
3.17805383034795, 2.70805020110221, 2.63905732961526, 2.19722457733622,
3.3322045101752, 2.19722457733622, 2.39789527279837, 0.693147180559945,
1.94591014905531, 3.09104245335832, 2.56494935746154, 2.07944154167984,
1.6094379124341, 2.07944154167984, 3.25809653802148, 2.39789527279837,
2.39789527279837, 2.56494935746154, 2.56494935746154, 3.36729582998647,
3.36729582998647, 3.17805383034795, 3.17805383034795, NA,
2.99573227355399, 3.04452243772342, 3.2188758248682, 3.3322045101752,
3.3322045101752, 3.3322045101752, 2.89037175789616, 2.39789527279837,
2.30258509299405, 3.29583686600433, 3.36729582998647, 3.13549421592915,
3.04452243772342, 3.04452243772342, 3.13549421592915, 3.2188758248682,
2.83321334405622, 2.30258509299405, 2.484906649788, 1.94591014905531,
3.49650756146648, 3.09104245335832, 2.83321334405622, 1.6094379124341,
3.09104245335832, 3.49650756146648, 2.70805020110221, 2.63905732961526,
2.56494935746154, 2.19722457733622, 3.25809653802148, 2.83321334405622,
2.63905732961526, 2.39789527279837, NA, 3.29583686600433,
2.39789527279837, 2.19722457733622, 2.19722457733622, 1.94591014905531,
3.52636052461616, 3.55534806148941, 3.43398720448515, 3.43398720448515,
3.43398720448515, 3.3322045101752, 3.25809653802148, 2.89037175789616,
3.09104245335832, NA, 3.29583686600433, 3.25809653802148,
3.17805383034795, 3.3322045101752, NA, 3.17805383034795,
2.56494935746154, 2.07944154167984, 2.19722457733622, 0,
3.40119738166216, 3.29583686600433, 3.40119738166216, 3.40119738166216,
3.43398720448515, 3.2188758248682, 2.77258872223978, 1.79175946922805,
1.79175946922805, 1.6094379124341, 3.17805383034795, 2.56494935746154,
2.19722457733622, 2.30258509299405, 2.484906649788, 3.52636052461616,
3.52636052461616, 3.58351893845611, NA, NA, 3.04452243772342,
2.07944154167984, 1.94591014905531, 2.07944154167984, 1.6094379124341,
3.46573590279973, 3.49650756146648, 3.17805383034795, NA,
NA, 3.52636052461616, 2.63905732961526, 2.484906649788, 2.83321334405622,
3.2188758248682, 3.40119738166216, 2.99573227355399, 2.30258509299405,
2.39789527279837, NA, 3.29583686600433, 3.36729582998647,
3.09104245335832, 2.94443897916644, 3.2188758248682, 3.58351893845611,
3.58351893845611, 1.94591014905531, 3.58351893845611, 3.04452243772342,
3.09104245335832, 3.17805383034795, 2.70805020110221, 3.43398720448515,
2.83321334405622, 3.40119738166216, 2.63905732961526, 2.39789527279837,
1.94591014905531, 2.19722457733622, 3.63758615972639, 3.49650756146648,
3.17805383034795, 3.13549421592915, 2.63905732961526, 3.3322045101752,
2.56494935746154, 1.38629436111989, 2.07944154167984, 2.19722457733622,
3.49650756146648, 3.17805383034795, 3.46573590279973, 2.07944154167984,
1.09861228866811, 3.36729582998647, 2.77258872223978, 0.693147180559945,
0.693147180559945, 1.6094379124341, 3.29583686600433, 1.6094379124341,
2.63905732961526, 1.09861228866811, 0.693147180559945, 3.58351893845611,
3.17805383034795, 3.09104245335832, 2.99573227355399, 3.13549421592915,
3.61091791264422, 3.36729582998647, 0.693147180559945, 3.09104245335832,
2.56494935746154, 3.29583686600433, 2.99573227355399, 2.99573227355399,
2.30258509299405, 2.39789527279837, 3.52636052461616, 2.70805020110221,
2.07944154167984, 1.94591014905531, 1.94591014905531, 3.43398720448515,
2.56494935746154, 3.17805383034795, 0, 0, 3.13549421592915,
2.83321334405622, 2.83321334405622, 1.09861228866811, 0,
3.46573590279973, 3.25809653802148, 3.17805383034795, 2.63905732961526,
2.94443897916644, 3.61091791264422, 2.83321334405622, 3.25809653802148,
2.484906649788, 2.99573227355399, 3.52636052461616, 3.55534806148941,
3.25809653802148, 3.36729582998647, 3.52636052461616, 3.46573590279973,
3.09104245335832, 3.61091791264422, 2.63905732961526, 2.484906649788,
3.3322045101752, 2.39789527279837, 2.63905732961526, 2.63905732961526,
2.63905732961526, 3.55534806148941, 3.55534806148941, 3.25809653802148,
3.3322045101752, 2.39789527279837, 3.52636052461616, 3.46573590279973,
2.63905732961526, NA, NA, 3.63758615972639, 3.58351893845611,
3.68887945411394, NA, NA, 3.71357206670431, 3.63758615972639,
2.94443897916644, NA, NA, 3.49650756146648, 3.13549421592915,
NA, NA, NA, 3.43398720448515, 3.29583686600433, 3.40119738166216,
NA, NA, 3.3322045101752, 3.04452243772342, NA, NA, NA), label = "HIV Test Value", format.spss = "F8.2", display_width = 10L)), class = c("tbl_df",
"tbl", "data.frame"), row.names = c(NA, -310L))
感谢您的帮助!
我想你正在寻找这样的东西:
library(dplyr)
library(ggplot2)
df %>%
group_by(condition, time) %>%
summarise(outcome = mean(outcome, na.rm = TRUE), .groups = "drop") %>%
ggplot(aes(x = time, y = outcome, color = as.factor(condition))) +
geom_point() +
geom_line() +
ylab("Estimated Marginal Means") +
scale_color_discrete(name = "Condition")
数据集以长格式布局,有一些缺失值,有 4 列, 第一列是“id”, 第二列是二进制变量“条件”, 第三列是变量“时间”, 第 4 个变量是“结果,
现在,我想用R创建一个剖面图,它显示在附件中的SPSS中。我知道如何使用SPSS创建它,但我不知道如何在R中执行此操作。(显示SPSS创建的图片的链接列在最后post)
原始数据集结构如下,
df <- structure(list(id = structure(c(101, 101, 101, 101, 101, 102,
102, 102, 102, 102, 103, 103, 103, 103, 103, 104, 104, 104, 104,
104, 105, 105, 105, 105, 105, 106, 106, 106, 106, 106, 107, 107,
107, 107, 107, 108, 108, 108, 108, 108, 109, 109, 109, 109, 109,
110, 110, 110, 110, 110, 111, 111, 111, 111, 111, 112, 112, 112,
112, 112, 113, 113, 113, 113, 113, 114, 114, 114, 114, 114, 115,
115, 115, 115, 115, 116, 116, 116, 116, 116, 117, 117, 117, 117,
117, 118, 118, 118, 118, 118, 119, 119, 119, 119, 119, 120, 120,
120, 120, 120, 121, 121, 121, 121, 121, 122, 122, 122, 122, 122,
123, 123, 123, 123, 123, 124, 124, 124, 124, 124, 126, 126, 126,
126, 126, 127, 127, 127, 127, 127, 129, 129, 129, 129, 129, 130,
130, 130, 130, 130, 131, 131, 131, 131, 131, 132, 132, 132, 132,
132, 133, 133, 133, 133, 133, 134, 134, 134, 134, 134, 135, 135,
135, 135, 135, 136, 136, 136, 136, 136, 137, 137, 137, 137, 137,
138, 138, 138, 138, 138, 139, 139, 139, 139, 139, 140, 140, 140,
140, 140, 201, 201, 201, 201, 201, 202, 202, 202, 202, 202, 203,
203, 203, 203, 203, 204, 204, 204, 204, 204, 205, 205, 205, 205,
205, 206, 206, 206, 206, 206, 207, 207, 207, 207, 207, 208, 208,
208, 208, 208, 210, 210, 210, 210, 210, 211, 211, 211, 211, 211,
212, 212, 212, 212, 212, 213, 213, 213, 213, 213, 214, 214, 214,
214, 214, 215, 215, 215, 215, 215, 216, 216, 216, 216, 216, 217,
217, 217, 217, 217, 218, 218, 218, 218, 218, 219, 219, 219, 219,
219, 220, 220, 220, 220, 220, 301, 301, 301, 301, 301, 302, 302,
302, 302, 302, 303, 303, 303, 303, 303, 304, 304, 304, 304, 304,
305, 305, 305, 305, 305), label = "Subject #", format.spss = "F11.0", display_width = 11L),
condition = structure(c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0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 4, 5, 1, 2, 3, 4, 5, 1,
2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5,
1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4,
5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3,
4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2,
3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1,
2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5,
1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4,
5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3,
4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2,
3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1,
2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5,
1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4,
5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3,
4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5), format.spss = "F4.0"),
outcome = structure(c(3.09104245335832, 2.89037175789616,
2.07944154167984, 2.30258509299405, 2.63905732961526, 3.58351893845611,
2.94443897916644, 2.19722457733622, 2.83321334405622, 2.99573227355399,
3.13549421592915, 2.89037175789616, 2.99573227355399, 2.70805020110221,
2.30258509299405, 3.43398720448515, 3.04452243772342, 2.56494935746154,
2.484906649788, 1.38629436111989, 3.25809653802148, 2.83321334405622,
2.484906649788, 2.56494935746154, 2.77258872223978, 3.55534806148941,
2.484906649788, 2.70805020110221, 1.38629436111989, 2.63905732961526,
3.49650756146648, 3.04452243772342, 2.70805020110221, 2.56494935746154,
2.484906649788, 3.2188758248682, 3.2188758248682, 3.09104245335832,
3.09104245335832, 3.09104245335832, 3.17805383034795, 3.17805383034795,
2.56494935746154, 2.30258509299405, 1.38629436111989, 3.13549421592915,
2.77258872223978, 2.77258872223978, NA, NA, 3.17805383034795,
3.17805383034795, 2.70805020110221, 2.63905732961526, 2.19722457733622,
3.3322045101752, 2.19722457733622, 2.39789527279837, 0.693147180559945,
1.94591014905531, 3.09104245335832, 2.56494935746154, 2.07944154167984,
1.6094379124341, 2.07944154167984, 3.25809653802148, 2.39789527279837,
2.39789527279837, 2.56494935746154, 2.56494935746154, 3.36729582998647,
3.36729582998647, 3.17805383034795, 3.17805383034795, NA,
2.99573227355399, 3.04452243772342, 3.2188758248682, 3.3322045101752,
3.3322045101752, 3.3322045101752, 2.89037175789616, 2.39789527279837,
2.30258509299405, 3.29583686600433, 3.36729582998647, 3.13549421592915,
3.04452243772342, 3.04452243772342, 3.13549421592915, 3.2188758248682,
2.83321334405622, 2.30258509299405, 2.484906649788, 1.94591014905531,
3.49650756146648, 3.09104245335832, 2.83321334405622, 1.6094379124341,
3.09104245335832, 3.49650756146648, 2.70805020110221, 2.63905732961526,
2.56494935746154, 2.19722457733622, 3.25809653802148, 2.83321334405622,
2.63905732961526, 2.39789527279837, NA, 3.29583686600433,
2.39789527279837, 2.19722457733622, 2.19722457733622, 1.94591014905531,
3.52636052461616, 3.55534806148941, 3.43398720448515, 3.43398720448515,
3.43398720448515, 3.3322045101752, 3.25809653802148, 2.89037175789616,
3.09104245335832, NA, 3.29583686600433, 3.25809653802148,
3.17805383034795, 3.3322045101752, NA, 3.17805383034795,
2.56494935746154, 2.07944154167984, 2.19722457733622, 0,
3.40119738166216, 3.29583686600433, 3.40119738166216, 3.40119738166216,
3.43398720448515, 3.2188758248682, 2.77258872223978, 1.79175946922805,
1.79175946922805, 1.6094379124341, 3.17805383034795, 2.56494935746154,
2.19722457733622, 2.30258509299405, 2.484906649788, 3.52636052461616,
3.52636052461616, 3.58351893845611, NA, NA, 3.04452243772342,
2.07944154167984, 1.94591014905531, 2.07944154167984, 1.6094379124341,
3.46573590279973, 3.49650756146648, 3.17805383034795, NA,
NA, 3.52636052461616, 2.63905732961526, 2.484906649788, 2.83321334405622,
3.2188758248682, 3.40119738166216, 2.99573227355399, 2.30258509299405,
2.39789527279837, NA, 3.29583686600433, 3.36729582998647,
3.09104245335832, 2.94443897916644, 3.2188758248682, 3.58351893845611,
3.58351893845611, 1.94591014905531, 3.58351893845611, 3.04452243772342,
3.09104245335832, 3.17805383034795, 2.70805020110221, 3.43398720448515,
2.83321334405622, 3.40119738166216, 2.63905732961526, 2.39789527279837,
1.94591014905531, 2.19722457733622, 3.63758615972639, 3.49650756146648,
3.17805383034795, 3.13549421592915, 2.63905732961526, 3.3322045101752,
2.56494935746154, 1.38629436111989, 2.07944154167984, 2.19722457733622,
3.49650756146648, 3.17805383034795, 3.46573590279973, 2.07944154167984,
1.09861228866811, 3.36729582998647, 2.77258872223978, 0.693147180559945,
0.693147180559945, 1.6094379124341, 3.29583686600433, 1.6094379124341,
2.63905732961526, 1.09861228866811, 0.693147180559945, 3.58351893845611,
3.17805383034795, 3.09104245335832, 2.99573227355399, 3.13549421592915,
3.61091791264422, 3.36729582998647, 0.693147180559945, 3.09104245335832,
2.56494935746154, 3.29583686600433, 2.99573227355399, 2.99573227355399,
2.30258509299405, 2.39789527279837, 3.52636052461616, 2.70805020110221,
2.07944154167984, 1.94591014905531, 1.94591014905531, 3.43398720448515,
2.56494935746154, 3.17805383034795, 0, 0, 3.13549421592915,
2.83321334405622, 2.83321334405622, 1.09861228866811, 0,
3.46573590279973, 3.25809653802148, 3.17805383034795, 2.63905732961526,
2.94443897916644, 3.61091791264422, 2.83321334405622, 3.25809653802148,
2.484906649788, 2.99573227355399, 3.52636052461616, 3.55534806148941,
3.25809653802148, 3.36729582998647, 3.52636052461616, 3.46573590279973,
3.09104245335832, 3.61091791264422, 2.63905732961526, 2.484906649788,
3.3322045101752, 2.39789527279837, 2.63905732961526, 2.63905732961526,
2.63905732961526, 3.55534806148941, 3.55534806148941, 3.25809653802148,
3.3322045101752, 2.39789527279837, 3.52636052461616, 3.46573590279973,
2.63905732961526, NA, NA, 3.63758615972639, 3.58351893845611,
3.68887945411394, NA, NA, 3.71357206670431, 3.63758615972639,
2.94443897916644, NA, NA, 3.49650756146648, 3.13549421592915,
NA, NA, NA, 3.43398720448515, 3.29583686600433, 3.40119738166216,
NA, NA, 3.3322045101752, 3.04452243772342, NA, NA, NA), label = "HIV Test Value", format.spss = "F8.2", display_width = 10L)), class = c("tbl_df",
"tbl", "data.frame"), row.names = c(NA, -310L))
感谢您的帮助!
我想你正在寻找这样的东西:
library(dplyr)
library(ggplot2)
df %>%
group_by(condition, time) %>%
summarise(outcome = mean(outcome, na.rm = TRUE), .groups = "drop") %>%
ggplot(aes(x = time, y = outcome, color = as.factor(condition))) +
geom_point() +
geom_line() +
ylab("Estimated Marginal Means") +
scale_color_discrete(name = "Condition")