Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does ggplot2 use/inherit some parameters in the R basic graphics?

Tags:

r

ggplot2

The reason why I ask this question is that I found the lwd parameter is in par() function reference but not in geom_boxplot() function. We all know that the parameters in par() function is for R basic graphics, while geom_boxplot() is a ggplot2 function. But when I add a code lwd=1.5 in the geom_boxplot(), the line width change 1.5 times than the default (just like the description in par() ). For example:

p <- ggplot(mpg, aes(class, hwy))
p + geom_boxplot(lwd=1.5)

It get a plot with thicker lines: enter image description here But when I use par(lwd=1.5) and just use geom_boxplot(), nothing changed to that ggplot:

par(lwd = 1.5)
p <- ggplot(mpg, aes(class, hwy))
p + geom_boxplot()

enter image description here So I have two questions:

  • Does the ggplot2 use/inherit some parameters in the R basic graphics, i.e parameters in par()?
  • If it does, why I use par(lwd = 1.5) or something similar to this form can not change anything to a ggplot2 picture?
like image 511
Leon Smith Avatar asked May 12 '26 00:05

Leon Smith


1 Answers

‘ggplot2’ doesn’t use the settings from par. It also doesn’t “inherit” any parameters from base graphics. Some ‘ggplot2’ functions merely accept the base R graphics names as aliases: lwd works instead of size, and pch works instead of shape.

But I wouldn’t use those, they’re undocumented and future versions of ‘ggplot2’ might stop accepting them (admittedly unlikely). Furthermore, the aliases don’t really make sense: geom_point(lwd = 5) works, even though a point obviously has no “line width”, so the parameter name is misleading.

like image 80
Konrad Rudolph Avatar answered May 13 '26 13:05

Konrad Rudolph