ggplot2--coordinate System Chapter

Source: Internet
Author: User

Directory:
    • Initial pattern
    • To modify the display range of an axis
    • Modify the label (content, size, font, color, bold, position, angle) of the axis
    • Modify the text (size, font, color, bold, position, angle) of the axis scale
    • Modify the contents of an axis scale text
    • To modify the scale interval for an axis

(For more information, see: R, Ggplot2, shiny summary)


Initial pattern:
Library(GGPLOT2)DT= data. Frame(A = 1:10, B = c(2,15,6,18,9,7,13,15,10,3), c = C ('a', 'C', 'a', 'B', 'C', 'D', 'a', ' C', 'D', 'B'))P= Ggplot (DT, AES (x =A, y =B, color =C, group = factor (1)) + geom_point (size =3.8) + geom_line (size =0.8) + Geom_text (AES (label =B, Vjust =1.1, Hjust =-0.5, Angle = $), Show_guide =FALSE# # # Add a value to a pointP


to modify the display range of an axis:
Library (ggplot2) dt = data.frame (A =1:Ten, B = C (2, the,6, -,9,7, -, the,Ten,3), C = C (' A ',' C ',' A ',' B ',' C ',' D ',' A ',' C ',' D ',' B ') p = ggplot (DT, AES (x = A, y = B,Color= C,Group= Factor (1)) + Geom_point (size=3.8) + Geom_line (size=0.8) + Geom_text (AES (label = B, Vjust =1.1, Hjust =-0.5,Angle= $), show_guide = FALSE) p + scale_x_continuous (limits = C (-5, the) # # Method one P + xlim (-5, the) # # Method two P + xlim (min(DT$A,0)*. 2,Max(DT$A)*. 2# # # General use multiple to limit the size, note the way to define the minimum value


Modify the label (content, size, font, color, bold, position, angle) of the axis:
Library(GGPLOT2)windowsfonts(MyFont = Windowsfont ("XXFarEastFont-Xingkai") # #如果要更改字体, you need to "bind" the font firstDT= data. Frame(A = 1:10, B = c(2,15,6,18,9,7,13,15,10,3), c = C ('a', 'C', 'a', 'B', 'C', 'D', 'a', ' C', 'D', 'B'))P= Ggplot (DT, AES (x =A, y =B, color =C, group = factor (1)) + geom_point (size =3.8) + geom_line (size =0.8) + Geom_text (AES (label =B, Vjust =1.1, Hjust =-0.5, Angle = $), Show_guide =FALSE)P+ Xlab ("This is the X-axis") + Ylab ("This is the Y axis") + Ggtitle ("This is the title") # # Modify Text Method oneP+ Labs (x ="This is the X-axis", y ="This is the Y axis", title ="This is the title") # # Modify Text Method two# # # Change the size, font, color, bold, position, Angle # # of X-axis labelsP+ Xlab ("This is the X-axis") + Theme (axis.title.x = element_text (size = the,Family="MyFont", color ="Green", face ="Bold", Vjust =0.5, Hjust =0.5, Angle = $))# # face value: Plain Normal, bold bold, italic italic, bold.italic italic Bold


Modify the text (size, font, color, bold, position, angle) of the axis scale:
Library(GGPLOT2)windowsfonts(MyFont = Windowsfont ("XXFarEastFont-Xingkai") # #如果要更改字体, you need to "bind" the font firstDT= data. Frame(A = 1:10, B = c(2,15,6,18,9,7,13,15,10,3), c = C ('a', 'C', 'a', 'B', 'C', 'D', 'a', ' C', 'D', 'B'))P= Ggplot (DT, AES (x =A, y =B, color =C, group = factor (1)) + geom_point (size =3.8) + geom_line (size =0.8) + Geom_text (AES (label =B, Vjust =1.1, Hjust =-0.5, Angle = $), Show_guide =FALSE)# # # #修改 the size, font, color, bold, position, and angle of the X-axis scale text:P+ Theme (Axis.text.x = element_text (size = the,Family="MyFont", color ="Green", face ="Bold", Vjust =0.5, Hjust =0.5, Angle = $))# # face value: Plain Normal, bold bold, italic italic, bold.italic italic Bold


to modify the contents of an axis scale text:
Library (ggplot2) dt = data.frame (A =1:Ten, B = C (2, the,6, -,9,7, -, the,Ten,3), C = C (' A ',' C ',' A ',' B ',' C ',' D ',' A ',' C ',' D ',' B ') p = ggplot (DT, AES (x = A, y = B,Color= C,Group= Factor (1)) + Geom_point (size=3.8) + Geom_line (size=0.8) + Geom_text (AES (label = B, Vjust =1.1, Hjust =-0.5,Angle= $), show_guide = FALSE) p + scale_x_continuous (BREAKS=DT$A, labels = dt$A*1000# # # Just changed the text on the scale


to modify the scale interval for an axis:
Library(GGPLOT2)DT= data. Frame(A = 1:10, B = c(2,15,6,18,9,7,13,15,10,3), c = C ('a', 'C', 'a', 'B', 'C', 'D', 'a', ' C', 'D', 'B'))P= Ggplot (DT, AES (x =A, y =B, color =C, group = factor (1)) + geom_point (size =3.8) + geom_line (size =0.8) + Geom_text (AES (label =B, Vjust =1.1, Hjust =-0.5, Angle = $), Show_guide =FALSE)P+ scale_x_continuous (BREAKS=SEQ (0,Ten,5))   ##XThe shafts are isolated from each5Units display a tick

Copyright NOTICE: Reprint Please indicate the source, thank you!

ggplot2--coordinate System Chapter

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.