当前位置:网站首页>Learn SCI thesis drawing skills (f)
Learn SCI thesis drawing skills (f)
2022-06-23 09:15:00 【Zhuangshan】
brief introduction
In the process of consulting the literature , I saw some very good published pictures , Today, I'll study with Xiaobian , How they use R Drawn out .

Today is mainly about Picture 6 (F) —— Four dimensional scatter diagram , This figure is also commonly used in scientific research drawings . It can display data of multiple dimensions .
The detailed code introduction of the first five figures can be seen : be based on R Detailed explanation of drawing skills of scientific research papers in language (4)、 be based on R Detailed explanation of drawing skills of scientific research papers in language (3) be based on R Detailed explanation of drawing skills of scientific research papers in language (2) be based on R Detailed explanation of drawing skills of scientific research papers in language (1) . The last picture will be introduced later , Readers in the process of learning , You can apply the internal knowledge points to your own graphics drawing . Twitter has listed the main knowledge points , It is more conducive for readers to learn and consult .
So let's see , How does the author realize this function , There are many knowledge points in this article , Let's study patiently , Suggest that you practice . The corresponding code 、 Data can be found in GitHub - marco-meer/scifig_plot_examples_R: Scientific publication figure plotting examples with R Find .
mapping
Load package
First, load some packages that need to be used .
library(ggplot2)
library(viridis) # Use color styles
Set the theme
Next , For convenience , The author set the theme before drawing , And name the function my_theme.
This part is in First tweet give , The complete code will be given at the end of the text .
Manually modify most panels , For details, please refer to this chapter article . Or watch me B Station issued 《R Language visualization course 》, There are also some simple topic settings .
Import data
use first read.csv() Import four-dimensional data , front 6 The row data is as follows .
data_F = read.csv("./data_F.csv")
head(data_F)
# K n amplitude duration
1 32.586025 3.065018 21.95444 2.3242144
2 9.012644 2.358836 60.16122 1.0029049
3 10.814589 1.829281 25.99396 0.5406435
4 23.560813 1.709909 61.18815 2.7394397
5 7.626436 1.566929 54.41945 0.7152433
6 15.295503 2.276775 39.79195 0.8423647
Drawing graphics
Draw a simple scatter diagram geom_point(),amplitude To set shape size ,duration As the filling basis .
base_size = 12
ggplot(data=data_F,
aes(x=K,y=n,
size=amplitude,
fill=duration))+
geom_point(pch=21)

Add theme , And modify it x、y Axis scales and labels .
Be careful :x Axis into logarithmic scale (
trans = 'log10').
my_theme() +
scale_x_continuous(expand = c(0, 0),
trans = 'log10',
labels=c(1,10,100),
breaks=c(1,10,100),
limits = c(1,100)) +
scale_y_continuous(expand = c(0, 0),
breaks=c(seq(0,4,by=0.5)),
limits = c(0,4)) + +
xlab(expression(paste("dissociation constant",~~italic("K")," (M)"))) +
ylab("Hill coefficient n")

Use annotation_logticks() Add logarithmic scale .scale_size(range = c(1, 3)) Modify the size range of scatter points . It also uses viridis Color styles in the package scale_fill_viridis(option="D"). Finally, modify the legend position theme(legend.position = c(0.9,0.35)).
annotation_logticks(sides='b') + # Add logarithmic scale
scale_size(range = c(1, 3)) + # The size range of the scatter
scale_fill_viridis(option="D") + # Color style
theme(legend.position = c(0.9,0.35)) # Change the legend position

however , There is a point at bottom that is not clearly shown , Here the author uses a trick ( The last article also used ), Show these points clearly . Let's see the effect of this code :
coord_cartesian(clip = "off")

Complete code
# Panel F ----
library(ggplot2)
library(vi)
base_size = 12
my_theme <- function() {
theme(
aspect.ratio = 1,
axis.line =element_line(colour = "black"),
# shift axis text closer to axis bc ticks are facing inwards
axis.text.x = element_text(size = base_size*0.8, color = "black",
lineheight = 0.9,
margin=unit(c(0.3,0.3,0.3,0.3), "cm")),
axis.text.y = element_text(size = base_size*0.8, color = "black",
lineheight = 0.9,
margin=unit(c(0.3,0.3,0.3,0.3), "cm")),
axis.ticks = element_line(color = "black", size = 0.2),
axis.title.x = element_text(size = base_size,
color = "black",
margin = margin(t = -5)),
# t (top), r (right), b (bottom), l (left)
axis.title.y = element_text(size = base_size,
color = "black", angle = 90,
margin = margin(r = -5)),
axis.ticks.length = unit(-0.3, "lines"),
legend.background = element_rect(color = NA,
fill = NA),
legend.key = element_rect(color = "black",
fill = "white"),
legend.key.size = unit(0.5, "lines"),
legend.key.height =NULL,
legend.key.width = NULL,
legend.text = element_text(size = 0.6*base_size,
color = "black"),
legend.title = element_text(size = 0.6*base_size,
face = "bold",
hjust = 0,
color = "black"),
legend.text.align = NULL,
legend.title.align = NULL,
legend.direction = "vertical",
legend.box = NULL,
panel.background = element_rect(fill = "white",
color = NA),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
plot.title = element_text(size = base_size,
color = "black"),
)
}
data_F = read.csv("./data_F.csv")
head(data_F)
panel_F <- ggplot(data=data_F,
aes(x=K,y=n,
size=amplitude,
fill=duration))+
geom_point(pch=21) +
my_theme() +
scale_x_continuous(expand = c(0, 0),
trans = 'log10',
labels=c(1,10,100),
breaks=c(1,10,100),
limits = c(1,100)) +
scale_y_continuous(expand = c(0, 0),
breaks=c(seq(0,4,by=0.5)),
limits = c(0,4)) +
xlab(expression(paste("dissociation constant",~~italic("K")," (M)"))) +
ylab("Hill coefficient n") +
annotation_logticks(sides='b') +
scale_size(range = c(1, 3)) +
scale_fill_viridis(option="D") + # a color palette from the viridis package
theme(legend.position = c(0.9,0.35)) +
coord_cartesian(clip = "off")
panel_F
Small make up has words
The main knowledge points learned in this paper are as follows :
- Use
annotation_logticks()Add logarithmic scale . - Use
scale_size()Modify the size range of scatter points ; - Use viridis Color styles in the package
scale_fill_viridis(); - Use
theme(legend.position = )Change the legend position .
After reading this article , Believe that your skill pack has more things . Remember to practice ! Reading it doesn't mean you will ~ If you find the content useful , Prepared by Xiaowen with intention . Give me a cup of coffee !
边栏推荐
- ARM中常见的英文解释
- [qnx hypervisor 2.2 user manual]6.1 using the QNX hypervisor system
- Redis learning notes - geographic information location (GEO)
- Redis learning notes - transactions
- Zone d'entrée du formulaire ionic5 et boutons radio
- An idea of using keep alive to cache data in vue3 form pages
- Use of type dependent names must be prefixed with 'typename'
- Structure binary tree from preorder and inorder traversal for leetcode topic analysis
- Custom tags - JSP tag enhancements
- 65. Valid Number
猜你喜欢

【学习资源】理解数学和热爱数学

Custom tag - JSP tag Foundation
Redis学习笔记—数据类型:哈希(hash)

Aiming at the overseas pet market, "grasshand" has developed an intelligent tracking product independent of mobile phones | early project
Redis learning notes - AOF of persistence mechanism

使用base64,展示图片
Redis学习笔记—Pipeline

学习SCI论文绘制技巧(F)

披萨订购设计----简单工厂模式

Redis learning notes RDB of persistence mechanism
随机推荐
RGB与CMYK颜色模式
Redis learning notes - redis and Lua
Redis learning notes - detailed explanation of redis benchmark
16.系统启动流程
cooding代码库的使用笔记
Leetcode topic analysis 3sum
学习SCI论文绘制技巧(E)
[event registration] sofastack × CSDN jointly held the open source series meetup, which was launched on June 24
GeoServer adding mongodb data source
点击添加下拉框
Basic process of code scanning login
Combination sum III of leetcode topic analysis
Redis学习笔记—事务
173. Binary Search Tree Iterator
Combination sum II of leetcode topic analysis
Redis learning notes - data type: string (string)
Redis学习笔记—redis-cli详解
12个球,有一个与其他不一样,提供一个天平,三次找出来
C#之Lambda不得不说的用法
986. Interval List Intersections