Ggplot2 Theme Related Settings-element_text

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.