ggplot2之设置绘图区域边框

本文记录了:

  • ggplot作图如何加粗边框的问题;
  • 修改这些参数除了加粗边框,还可以有更多的效果。

0. 加载【ggplot2】包

library(ggplot2)

1. 示例数据

data <- data.frame(
  x = c(1, 2, 3, 4, 5),  
  y = c(1, 3, 5, 2, 4)
  )

2. 默认作图

ggplot(data, aes(x = x, y = y)) +
  geom_point()

ggplot2之设置绘图区域边框

3. 加粗边框后

ggplot(data, aes(x = x, y = y)) +
  geom_point() +
  theme(panel.border = element_rect(fill=NA,
                                    color="black", 
                                    size=2, 
                                    linetype="solid")

ggplot2之设置绘图区域边框

补充
element_rect(): 表明要设置的元素类型为矩形。
fill = NA: 设置矩形的填充颜色为透明,即不填充任何颜色。
color = "black": 设置矩形的边框颜色为黑色。
size = 2: 设置矩形的边框大小为5个单位。
linetype = "solid": 设置矩形的边框线型为实线。
angle: 设置矩形边框的角度(以度为单位)。
lineend: 设置矩形边框线的末端样式(”butt”, “round”, “square”)。
linejoin: 设置矩形边框线的连接样式(”mitre”, “round”, “bevel”)。
linemitre: 设置矩形边框线的倒角限制(数值)。

ggplot2之设置绘图区域边框

我的代码
https://github.com/wPencil/MyNotes/blob/d960d4734d506e3e00c2a085ab312205de5b0a94/R/ggplot2/ggplot2_panel.border/ggplot2_panel.border.R

© 版权声明
THE END
如果内容对您有所帮助,就支持一下吧!
点赞0 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容