After Geom settings and scale settings, to make the picture beautiful, the theme setting is not less than
Element_text () is an important piece of content in the theme settings
Element_text(Family =Null, Face =Null, Colour =Null, size =Null, Hjust =Null, Vjust =Null, Angle =Null, lineheight =Null)
Parameter family represents a font style
The parameter face represents the font format, the desired value ("plain", "italic", "bold", "Bold.italic")
Parameter colour indicates font color
Parameter size indicates font size
Parameter hjust to adjust the horizontal distance, adjustable range 0 to 1
Parameter vjust is used to adjust the vertical distance, adjustable range 0 to 1
parameter angle for adjusting the tilt of the font, adjusting the range 0 to 360
Parameter lineheight indicates line height
Let's look at a specific example:
Library (Ggplot2) P<-ggplot (Economics,aes (Pop,unemploy)) +geom_point (p+labs "Population", x= "unemployment", y= "economic Investigation report")
Next we use Element_text () to adjust the text
Windowsfonts (MyFont = Windowsfont ("Microsoft Jas")) P+labs (x= "Population", y= "unemployment", title= "economic Investigation Report") + Theme (Title=element_text ( Family= "MyFont", size=12,color= "Red", face= "italic", hjust=0.2,lineheight=0.2))
After a few tweaks, the font on the headline changed a lot compared to the original.
In addition, the above directly uses the title setting, which changes the text style that includes the chart title, x-axis, y-axis, and legend. If you just change a style, you can use a separate setting. Like what
P+labs (x= "Population", y= "unemployment rate", title= "economic Investigation Report") + Theme (Title=element_text (family= "MyFont", size=12,color= "Red", Face= "Italic", hjust=0.2,lineheight=0.2), axis.title.x=element_text (size=10,face= "bold", Color= "Blue", hjust= 0.5), axis.title.y=element_text (size=14,color= "green", hjust=0.5,angle=45), Axis.text.x=element_text ( Family= "MyFont", size=8,color= "Red"))
It is obvious that there is a big change in the text, where axis.title.x represents the x-axis title, while Axis.text.x represents the x-axis scale label.
Ggplot2 Theme Related Settings-element_text