I have this dataset:
structure(list(Subscales = c("Self-Regulation", "Self-Efficacy",
"Personal Accomplishment", "Being in Shape", "Injury", "Emotional Exhaustion",
"Disturbed Breaks", "Sleep Quality", "General Well-Being", "Physical Recovery",
"Social Recovery", "Success", "Physical Complaints", "Lack of Energy",
"Fatigue", "Conflicts/Pressure", "Social Stress", "Emotional Stress",
"General Stress"), MP1 = c(3.51, 3.34, 2.64, 3.58, 1.84, 1.46,
1.26, 4.29, 3.84, 3.44, 3.46, 2.68, 1.69, 1.93, 1.86, 1.78, 1.8,
1.68, 1.69), MP2 = c(3.47, 3.26, 2.57, 3.4, 1.89, 1.45, 1.26,
4.21, 3.87, 3.47, 3.43, 2.54, 1.8, 1.81, 1.99, 2.03, 1.93, 1.8,
1.73), MP3 = c(3.5, 3.37, 2.8, 3.37, 1.98, 1.46, 1.31, 4.16,
4.03, 3.45, 3.85, 2.79, 1.85, 1.63, 2.14, 1.91, 1.89, 1.7, 1.5
), Skalen = structure(c(15L, 14L, 11L, 1L, 9L, 4L, 3L, 16L, 8L,
13L, 17L, 19L, 12L, 10L, 6L, 2L, 18L, 5L, 7L), .Label = c("Being in Shape",
"Conflicts/Pressure", "Disturbed Breaks", "Emotional Exhaustion",
"Emotional Stress", "Fatigue", "General Stress", "General Well-Being",
"Injury", "Lack of Energy", "Personal Accomplishment", "Physical Complaints",
"Physical Recovery", "Self-Efficacy", "Self-Regulation", "Sleep Quality",
"Social Recovery", "Social Stress", "Success"), class = "factor")), row.names = c(NA,
-19L), class = c("tbl_df", "tbl", "data.frame"))
And created this plot:
ggplot(data=ebf, aes(x=forcats::fct_inorder(Subscales), y=MP1, group=""))
geom_line(aes(y = MP1, linetype="MP1", color = "MP1"))
geom_line(aes(y = MP2, linetype="MP2", color = "MP2"))
geom_line(aes(y = MP3, linetype="MP3", color = "MP3"))
geom_point(aes(y = MP1, shape ="MP1", color = "MP1"))
geom_point(aes(y = MP2, shape ="MP2", color = "MP2"))
geom_point(aes(y = MP3, shape ="MP3", color = "MP3"))
coord_flip()
labs(x="RESTQ-Sport Subscales", color = "Legend:", linetype = "Legend:", shape = "Legend:")
scale_color_manual(values = colors)
scale_y_continuous(limits = c(0, 6), breaks = c(0,1,2,3,4,5,6), labels = paste0(0:6, "\n", labels.minor), sec.axis = sec_axis(~.x, breaks = 0:6))
theme(panel.grid.major.y = element_blank(),panel.grid.minor.x = element_blank(),axis.line.x = element_line(size = 1, colour = "black", linetype=1),axis.title=element_blank(),legend.position="bottom")
For a better illustration, I want to adjust lines and shape of the graph. The lines should be a little bit thicker and the shapes a litte bit bigger.
So I changed my code like this, as I did it for previous ggplot graphs before:
ggplot(data=ebf, aes(x=forcats::fct_inorder(Subscales), y=MP1, group=""))
geom_line(aes(y = MP1, linetype="MP1", color = "MP1", size = 1))
geom_line(aes(y = MP2, linetype="MP2", color = "MP2", size = 1))
geom_line(aes(y = MP3, linetype="MP3", color = "MP3", size = 1))
geom_point(aes(y = MP1, shape ="MP1", color = "MP1", size = 3))
geom_point(aes(y = MP2, shape ="MP2", color = "MP2", size = 3))
geom_point(aes(y = MP3, shape ="MP3", color = "MP3", size = 3))
coord_flip()
labs(x="RESTQ-Sport Subscales", color = "Legend:", linetype = "Legend:", shape = "Legend:")
scale_color_manual(values = colors)
scale_y_continuous(limits = c(0, 6), breaks = c(0,1,2,3,4,5,6), labels = paste0(0:6, "\n", labels.minor), sec.axis = sec_axis(~.x, breaks = 0:6))
theme(panel.grid.major.y = element_blank(),panel.grid.minor.x = element_blank(),axis.line.x = element_line(size = 1, colour = "black", linetype=1),axis.title=element_blank(),legend.position="bottom")
But not matter how I define line and shape size, the result is always way to big shapes or way to thick lines like this:
I don't know how to adjust this, to get a pretty graph with adequate lines and shapes.
Thanks in advance, I appreciate any kind of help.
Cheers
CodePudding user response:
I ran into some issues while running your code, so I had to modify this code chunk below. But what was likely causing your issues is that you put the size
argument inside aes()
. If you pull size
out, then you are able to adjust the size of the lines and points.
ggplot(data=ebf, aes(x=forcats::fct_inorder(Subscales), y=MP1, group=""))
geom_line(aes(y = MP1, linetype="MP1", color = "MP1"), size = 1)
geom_line(aes(y = MP2, linetype="MP2", color = "MP2"), size = 1)
geom_line(aes(y = MP3, linetype="MP3", color = "MP3"), size = 1)
geom_point(aes(y = MP1, shape ="MP1", color = "MP1"), size = 3)
geom_point(aes(y = MP2, shape ="MP2", color = "MP2"), size = 3)
geom_point(aes(y = MP3, shape ="MP3", color = "MP3"), size = 3)
coord_flip()
labs(x="RESTQ-Sport Subscales", color = "Legend:", linetype = "Legend:", shape = "Legend:")
CodePudding user response:
As Harrison Jones already mentions we are missing labels.minor
and color
to completely reproduce your plot. So I also skipped those lines. He also correctly points out, that the size argument beeing in the aes
call is your issue. I would like to additionally point out, that your plotting could be much easier and shorter if your data was in a tidy data format (one row per observation). This would circumvent the need for three calls of geom_line
and geom_point
and you could define all the aesthetics in the ggplot call and don't need to repeat them.
ebf %>%
pivot_longer(cols = MP1:MP3, names_to = "MP", values_to = "values") %>%
ggplot(aes(x=forcats::fct_inorder(Subscales), y = values, group = MP, color = MP, linetype = MP))
geom_line()
geom_point(size = 2)
coord_flip()
labs(x="RESTQ-Sport Subscales", color = "Legend:", linetype = "Legend:", shape = "Legend:")
theme(panel.grid.major.y = element_blank(),panel.grid.minor.x = element_blank(),axis.line.x = element_line(size = 1, colour = "black", linetype=1),axis.title=element_blank(),legend.position="bottom")