Reputation:
I am trying to add a geom_smooth line of the average of Size to the code.
ggplot(data = Birds,
aes(Species, size, color=Subject)) +
geom_line() +
labs (x = "Species",
y = "Size(cm)",
title = "Size and Species of Birds") +
theme_bw()
Upvotes: 2
Views: 501
Reputation: 447
Is this what you're looking for? Adding color=Subject
to the aes
will create a different line for each subject. Because each subject has received different doses, but they are measured at the same time intervals, plottling geom_line() creates some funky results if you don't split the lines based on subject. In other words, you have multiple y values for a single x value.
ggplot(data = Theoph,
aes(Time, conc)) +
geom_smooth()+
#geom_line() +
geom_point() +
labs (x = "Time after dose (hours)",
y = "Theophylline oncentration (mg/L)",
title = "Theophylline concentration in all subjects over time") +
coord_equal() +
theme_bw()
If you wanted just a single clean line for the average, you could do that outside of the ggplot
"pipe", then plot the new average. There is probably a way to do it all in ggplot
though, I just don't know.
Upvotes: 1