当前位置:网站首页>Ggplot facet detail adjustment summary
Ggplot facet detail adjustment summary
2022-07-07 03:51:00 【Zhuang Shanshan】
brief introduction
Xiaobian introduced some time ago ggplot2 Faceted problem :R Visible | Split one page and many pictures . And many books have introduced How to use ggplot2 Facet of , Such as :《ggplot2: Elegant Graphics for Data Analysis》,《R Language course 》.
But the detail adjustment after painting , Hardly introduced . Xiaobian is in the process of learning , Some detail adjustment skills are sorted out , For reference . And share it with you , I hope I can help you ~
The framework of this paper

course
This paper gives an example by simulating data , Readers can use the data form , Load your own dataset , And corresponding data processing .
Generate the data
# Import package
library(ggplot2)
set.seed(1)
dat = data.frame("time" = rep(2013:2019,6),
"method" = rep(LETTERS[1:6],each = 7),
"value" = rnorm(7*6,5,1),
"upper" = rnorm(7*6,5,1) + abs(rnorm(7*6,2,0.1)),
"lower" = rnorm(7*6,5,1) - abs(rnorm(7*6,2,0.1))
)
head(dat)

Basic version drawing
cols <- c("#85BA8F", "#A3C8DC","#349839","#EA5D2D","#EABB77","#F09594") # Set the color
p = ggplot(dat,aes(x = time, y = value,fill = method)) +
geom_line(aes(color = method)) + # Add line
geom_point(aes(color = method)) + # Add scatter
geom_ribbon(aes(ymin=lower, ymax=upper), alpha=0.3) + # Add interval
scale_x_continuous(breaks = 2013:2019) +
facet_wrap(vars(method),nrow = 4) +
theme_bw() + ylab("Value") + xlab("Time") + # Theme Settings
theme(panel.grid = element_blank())
p

Scale modification
By default ,x、y The axis scale is fixed , namely ,scales = "fixed". For details, please refer to :https://ggplot2-book.org/facet.html.
x Axis
Using the parameter scales = "free_x", modify x Shaft scale .
p + facet_wrap(vars(method),nrow = 4,scales = "free_x")

y Axis
Using the parameter scales = free_y, modify y Shaft scale .
p + facet_wrap(vars(method),nrow = 4,scales = "free_y")

Double axis
Using the parameter scales = free, modify x and y Shaft scale .
p + facet_wrap(vars(method),nrow = 4,scales = "free")
[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-q8BdFXbf-1656937310384)(https://files.mdnice.com/user/5000/9d1e15c9-ebc3-43b2-a892-43a1229eb0b5.png)]
Title box adjustment
This part is all about theme() Adjust in . For details, please refer to :https://ggplot2-book.org/polishing.html.
Position adjustment
modify strip.position Adjust the position .
p + facet_wrap(vars(method),nrow = 3,strip.position = "left")

Remove the title box background
utilize strip.background = element_blank() Remove the title box background .
p + theme(
strip.background = element_blank() # Remove the title box background
)

Change the background color of the title box
utilize strip.background = element_rect() Change the background color of the title box .
p + theme(strip.background=element_rect(colour="black",
fill="#2072A8"))

Change the text color of the title box
utilize strip.text.x=element_text() Change the text color of the title box .
p + theme(strip.text.x=element_text(colour="white"))

Delete the title box
utilize strip.text.x = element_blank() Delete the title box .
p + theme(strip.text.x = element_blank())

Small make up has words
If it helps , Welcome to thumb up , Share ~
边栏推荐
- Free PHP online decryption tool source code v1.2
- 运算放大器应用汇总1
- [hcie TAC] question 3
- Class常量池与运行时常量池
- MySQL的索引
- 22. (ArcGIS API for JS) ArcGIS API for JS Circle Collection (sketchviewmodel)
- Flutter3.0, the applet is not only run across mobile applications
- [leetcode] 700 and 701 (search and insert of binary search tree)
- 浅谈网络安全之文件上传
- 【开发软件】 tilipa开发者软件
猜你喜欢

ggplot 分面的细节调整汇总

【mysql】mysql中行排序

代码质量管理

VHDL implementation of single cycle CPU design

R data analysis: how to predict Cox model and reproduce high score articles

Clock in during winter vacation

20. (ArcGIS API for JS) ArcGIS API for JS surface collection (sketchviewmodel)

25. (ArcGIS API for JS) ArcGIS API for JS line modification line editing (sketchviewmodel)

SQL injection -day15
![[development software] tilipa Developer Software](/img/b8/de2a1ea6474bb3f9b44e7ea01c441b.png)
[development software] tilipa Developer Software
随机推荐
codeforces每日5题(均1700)-第七天
[development software] tilipa Developer Software
19.(arcgis api for js篇)arcgis api for js线采集(SketchViewModel)
Probability formula
GPT-3当一作自己研究自己,已投稿,在线蹲一个同行评议
20. (ArcGIS API for JS) ArcGIS API for JS surface collection (sketchviewmodel)
ERROR: Could not build wheels for pycocotools which use PEP 517 and cannot be installed directly
23. (ArcGIS API for JS) ArcGIS API for JS ellipse collection (sketchviewmodel)
22. (ArcGIS API for JS) ArcGIS API for JS Circle Collection (sketchviewmodel)
如何检测mysql代码运行是否出现死锁+binlog查看
A 股指数成分数据 API 数据接口
Codeworks 5 questions per day (1700 average) - day 7
Adaptive non European advertising retrieval system amcad
我的勇敢对线之路--详细阐述,浏览器输入URL发生了什么
termux设置电脑连接手机。(敲打命令贼快),手机termux端口8022
Enumeration general interface & enumeration usage specification
HW notes (II)
【安全攻防】序列化與反序列,你了解多少?
HW-小记(二)
Arduino droplet detection