很多时候我们做柱状图组合折线图,或者双变量折线图,这时候需要设置双坐标轴,如果两组数据数值相差太大,会使得图的展示不合理,设置双坐标轴,各自使用各自坐标,则会对比明显。双坐标轴作图prism和original都可以实现,这里我们使用ggplot2实现。
读入数据并加载R包。
df<-read.csv("A.csv",header = T)
library(ggpubr)
library(scales)
library(ggplot2)
colnames(df)
ggplot(df, aes(y=M0_like,x=Diameter))+
geom_line(color="#6FB585")+
geom_point(size=3,color="#6FB585")+
geom_line(aes(y=M1_like,x=Diameter), color="#E8BF80")+
geom_point(aes(y=M1_like, x=Diameter),size=3,color="#E8BF80")
ggplot(df, aes(y=M0_like,x=Diameter))+
geom_line(color="#6FB585")+
geom_point(size=3,color="#6FB585")+
geom_line(aes(y=M1_like,x=Diameter), color="#E8BF80")+
geom_point(aes(y=M1_like, x=Diameter),size=3,color="#E8BF80")+
scale_y_continuous(sec.axis = sec_axis(~.*1, name = 'M1_like'))+
theme_bw()+
theme(panel.grid.major=element_blank(),panel.grid.minor=element_blank())+
theme(panel.border = element_blank())+
theme(axis.line = element_line(colour = "black",size = 1))+
theme_classic(base_size = 15)
ggplot(df, aes(y=M0_like,x=Diameter))+
geom_line(color="#6FB585")+
geom_point(size=3,color="#6FB585")+
scale_y_continuous(expand = c(0,0),limits = c(0,6500),
sec.axis = sec_axis(~./5,
name = 'M1_like',
breaks = seq(0,1000,200)))+
geom_line(aes(y=`M1_like`*5,x=Diameter), color="#E8BF80")+
geom_point(aes(y=`M1_like`*5, x=Diameter),size=3,color="#E8BF80")+
theme_bw()+
theme(panel.grid.major=element_blank(),panel.grid.minor=element_blank())+
theme(panel.border = element_blank())+
theme(axis.line = element_line(colour = "black",size = 1))+
theme_classic(base_size = 15)
library(grid)
setwd("C:\\Users\\msy\\Documents\\work\\年度")
shuaxin<
-
read.csv("总体test.csv",stringsAsFactors = FALSE)
shuaxin
p1<
-
ggplot
(shuaxin,a
对于研究过
ggplot
2的人而言,一个很奇怪的问题就是,为什么
ggplot
2做
双坐标轴
那么难?(解决方案可以参见Stack Overflow的这个问题。)
作者给出的理由
但事实上,作者并不建议使用双轴,这是他没有在
ggplot
2提供相关解决方案的原因,可以参见这个答案。
摘录如下:
It's not possible in ggplo...
对于2015年才出现的SD
-
WAN,一直处在“一个名词,各自表述”的尴尬中。但由于其在当前的网络圈太火爆的缘故,已经到了“脚踢VPN,拳打路由器”的地步,各路厂商纷纷易帜,不管有的没的,都言必称自己的家当就是SD
-
WAN,以至于各位看官也不清楚谁是谁非,只能袖手旁观,看个热闹。
趁着Abloomy在市场上发布自研的SD
-
WAN产品之际,我对SD
-
WAN见诸于媒体文章的概念讨论进行了整理,试图给出有...
library(tidyverse)
df4 <
-
tibble(
year = c("2013", "2014", "2015", "2016", "2017", "2018", "2019", "2020"),
ResearchInput = c(1.56, 2.54, 2.99, 5.63, 11.08, 12.31, 16.77, 25.92),
ProportioninOperatingIncome = c(6.8, 6.9, 5, 4.9,
两个
ggplot
图合并到一起,一个x轴两个y轴raw_data <
-
read_delim('./data/GO_pathway.txt', delim = '\t')
head(raw_data)
library(dplyr)
library(Cairo)double_y_axis <
-
function(p1, p2){
g1 <
-
ggplot
_gtable(
ggplot
_build(p