我已经使用ggplot和plotly进行了可视化(请参见下面的代码)
Figure1 <- ggplot(MergeAll, aes(theme_classic())) +
geom_jitter(mapping = aes(x = count_call, y = Mean_11_1, color= "call"), na.rm = TRUE) +
geom_jitter(mapping = aes(x = count_sms, y = Mean_11_1, color= "sms"), na.rm = TRUE) +
geom_jitter(mapping = aes(x = count_call, y = Mean_05_2, color= "call"), na.rm = TRUE) +
geom_jitter(mapping = aes(x = count_sms, y = Mean_05_2, color= "sms"), na.rm = TRUE) +
geom_smooth(mapping = aes(x = total, y = Mean_11_1, color = "Mean_11_1"), na.rm = TRUE, se = FALSE) +
geom_smooth(mapping = aes(x = total, y = Mean_05_2, color= "Mean_05_2"), na.rm = TRUE, se = FALSE) +
coord_cartesian(xlim = c(0, 4000)) +
labs(title = "Relationship between phone interaction (calls+SMS) and life satisfaction",
subtitle = "Life satisfaction in the months may and november of 2010",
caption = "Data from the Friends and Family Dataset.",
tag = "Figure 1",
x = "Telephone Interaction (call + text)",
y = "Average Life satisfaction (5-point scale)",
colour = "Legenda") +
scale_color_discrete(labels = c("Call", "May 2010", "November 2010", "SMS")) +
theme(axis.text.x = element_text(size = 10), axis.title.x = element_text(size = 12),
axis.text.y = element_text(size = 10), axis.title.y = element_text(size = 12),
plot.title = element_text(size = 12, face = "bold", color = "darkgreen"))
ggplotly(Figure1, tooltip = c(hoverinfo = "count_call", "count_sms", "Mean_05_2", "Mean_11_1"))
这已经使我永远忘却了,我对现在的样子感到满意。但是,我一直在尝试根据性别更改数据点的形状。
geom_jitter(mapping = aes(x = count_call, y = Mean_11_1, color= "call", shape= "Gender"), na.rm = TRUE) +
geom_jitter(mapping = aes(x = count_sms, y = Mean_11_1, color= "sms", shape = "Gender"), na.rm = TRUE) +
geom_jitter(mapping = aes(x = count_call, y = Mean_05_2, color= "call", shape = "Gender"), na.rm = TRUE) +
geom_jitter(mapping = aes(x = count_sms, y = Mean_05_2, color= "sms", shape = "Gender"), na.rm = TRUE) +
但是,这不起作用(没有错误消息,看起来很奇怪。
head(MergeAll)
# A tibble: 6 x 9
# Groups: participantID [3]
participantID Mean_05_2 Mean_11_1 count_sms n.x count_call n.y Gender total
<chr> <dbl> <dbl> <int> <int> <int> <int> <fct> <int>
1 sp10-01-05 6.11 NA 76 76 434 434 female 1020
2 sp10-01-05 6.11 NA 76 76 434 434 female 1020
3 sp10-01-06 NA 5.33 116 116 201 201 male 634
4 sp10-01-06 NA 5.33 116 116 201 201 male 634
5 sp10-01-07 5.78 6 3107 3107 1465 1465 male 9144
6 sp10-01-07 5.78 6 3107 3107 1465 1465 male 9144
有人可以帮我吗?提前非常感谢您。