Morning,
My file contains longitudinal data. To create my graph, I used qualitative variables. How to obtain different values of Y for each of the modalities of the variables? Y : as the number of observations per individual at each time of X.
Data : df
id = c(1, 1, 1, 2, 3, 3, 3, 4, 5, 5, 5, 6, 7, 7, 7, 8, 8, 8, 9, 9, 9),
test1 = c("fait", "fait", "fait", "nonfait", "fait", "fait", "fait", "fait", "fait", "fait", "fait", "nonfait", "fait", "fait", "fait", "nonfait", "nonfait", "fait", "fait", "fait", "nonfait"),
infpalu1 = c("0", "0", "0", NA, "0", "2", NA, "0", "0", "0", "1", NA, "0", "0", "0", NA, NA, "0", "0", "0", NA),
question = c("vmbis", "vmbis", "vmbis", "vmbis", "vmbis", "vmbis", "vmbis", "vmbis", "vmbis",
"vmbis", "vmbis", "vmbis", "vmbis", "vmbis", "vmbis", "vmbis", "vmbis", "vmbis", "vmbis", "vmbis", "vmbis"),
reponse = c("12_vsys", "18_vsys", "24_vsys", "24_vsys", "12_vsys", "18_vsys", "24_vsys","12_vsys", "12_vsys", "18_vsys", "24_vsys", "12_vsys", "12_vsys", "18_vsys", "24_vsys", "12_vsys", "18_vsys", "24_vsys", "12_vsys", "18_vsys", "24_vsys"))
df <- data.frame(id, test1, infpalu1, question, reponse)
Long file : df_long1
df_long <- df |> pivot_longer(-c(id, reponse))
df_long1 <- df_long %>%
drop_na()
R code Graph
ggplot(df_long1, aes(x= reponse, y = value)) +
geom_bar(aes (fill = name), colour = "#006ddb", position = "dodge", stat = "identity") +
scale_fill_manual(values = c("#DF536B", "#F0E442","#E69F00" )) +
theme(axis.text.x = element_text(angle = 90, vjust = 0.5)) +
ggtitle("Nb tests, infections palustres, observations / visite")
Graph :
R code pour solve this problem !
Thanks.
New contributor
user25334460 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.