Я сделал визуализацию, используя 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
Может, кто-то может мне помочь? Заранее большое спасибо.