日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

修改element默认样式_ggplot2作图:修改主题元素的外观样式(整体修改)

發布時間:2025/4/5 编程问答 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 修改element默认样式_ggplot2作图:修改主题元素的外观样式(整体修改) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

一、修改基礎圖形的樣式

library(ggplot2)

library(gcookbook) # Load gcookbook for the heightweight data set

# Create the base plot

hw_plot <- ggplot(heightweight, aes(x = ageYear, y = heightIn, colour = sex)) +

geom_point()

# Options for the plotting area,修改基本圖形的外觀

hw_plot +

theme(

#設置主網格線

panel.grid.major = element_line(colour = "red"),

#設置副網格線

panel.grid.minor = element_line(colour = "red", linetype = "dashed",

size = 0.2),

#設置背景色

panel.background = element_rect(fill = "lightblue"),

#設置邊界

panel.border = element_rect(colour = "blue", fill = NA, size = 2)

)

二、設置圖例樣式

# Options for the legend,圖例

hw_plot +

theme(

#設置圖例的背景、標題、文本、小方框等

legend.background = element_rect(fill = "grey85", colour = "red", size = 1),

legend.title = element_text(colour = "blue", face = "bold", size = 14),

legend.text = element_text(colour = "red"),

legend.key = element_rect(colour = "blue", size = 0.25)

)

三、設置坐標軸和坐標軸文本樣式

# Options for text items

hw_plot +

ggtitle("Plot title here") +

theme(

axis.title.x = element_text(colour = "red", size = 14),

axis.text.x = element_text(colour = "blue"),

axis.title.y = element_text(colour = "red", size = 14, angle = 90),

axis.text.y = element_text(colour = "blue"),

plot.title = element_text(colour = "red", size = 20, face = "bold")

)

四、設置分面樣式

# Options for facets

hw_plot +

facet_grid(sex ~ .) +

theme(

strip.background = element_rect(fill = "pink"),

strip.text.y = element_text(size = 14, angle = -90, face = "bold")

)

# strip.text.x is the same, but for horizontal facets;如果是沿著x軸水平分面,那么則設置 strip.text.x

五、使用已有主題并微調細節

比如使用theme_bw(),需將其寫在前面,微調的theme()語句寫在后面,如下:

hw_plot +

theme_bw() +

theme(axis.title.x = element_text(colour = "red", size = 12))

不再貼圖。

涉及設置細節網絡查找或參考《R數據可視化手冊》9.4節。

總結

以上是生活随笔為你收集整理的修改element默认样式_ggplot2作图:修改主题元素的外观样式(整体修改)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。