I want to konw how could I get a graph with geom_smooth, but I want to a line in the legend without shade (eg:confidence interval). In a short, graph have a shade (confidence interval)such as graph1, legend have no a shade such as graph2. Thank you!
Asked
Active
Viewed 234 times
1 Answers
0
First I loaded ggplot and added mtcars library to explain.
library(ggplot2)
cars <- mtcars
This is a normal ggplot graph with geom_smooth and the confidence interval.
ggplot(cars, aes(x = mpg, y= disp)) + geom_point() + geom_smooth()
within geom_smooth is an option se which is your confidence interval. se is default set to TRUE by setting se to FALSE it removes the confidence interval.
ggplot(cars, aes(x = mpg, y= disp)) + geom_point() + geom_smooth(se = FALSE)
for other geom_smooth options see
?geom_smooth
I Hope this helps!

Michael Cantrall
- 313
- 3
- 15
-
Thank you for answer. I want to get a graph with a se (geom_smooth(se = T)), but a legend with a se was not expected. In short, graph 1with a legend such as graph2 in my example. – James Gao Mar 05 '18 at 00:44
-
Oh Im sorry, If you mean to remove the background of the icons for the legend - as far as I understand this is semi-impossible. The icons themselves are snippets of the line around a point they are not made separately - any background on the line itself is applied to the icon in the legend. Here is a link to the tidyverse web-page on legend formatting:http://ggplot2.tidyverse.org/reference/guide_legend.html – Michael Cantrall Mar 05 '18 at 05:38
-
Now I say semi because you can replace the icon with your own icon or label but that would require you to remake all the icons and honestly I don't see how it is worth the time but you can check it out here: https://stackoverflow.com/questions/10405823/changing-the-symbol-in-the-legend-key-in-ggplot2 – Michael Cantrall Mar 05 '18 at 05:39
-
Thank you very much! I will have a look at these linkages you send. – James Gao Mar 05 '18 at 07:05