1、https://ggplot2.tidyverse.org/reference/sec_axis.html 2、https://www.r-graph-gallery.com/line-chart-dual-Y-axis-ggplot2.html 3、https://github.com/alex-koiter/Weather-and-Climate-figures 4、https://twitter.com/Alex_Koiter/status/1312458166496501760/photo/1 代码主要来自于链接3 首先是准备...
R语言 | 绘制双Y轴 禾堇 穷则变,变则通,通则久。2 人赞同了该文章 参考:Dual Y axis with R and ggplot2 – the R Graph Gallery (r-graph-gallery.com) (1)加载包 # Libraries library(ggplot2) library(dplyr) library(patchwork) # To display 2 charts together # library(hrbrthemes) 这里没...
p2<-ggplot(df, aes(x = x, y = y2))+ geom_line(color="green",size=1) cowplot::plot_grid(p1,p2,ncol = 2) 绘制双Y轴图形 ggplot2包中绘制双Y轴折线图主要依靠sec.axis()函数实现,但是这个函数是允许在第一个Y轴基础上建立第二个Y轴,并不是重新建立独立的y轴,而且此函数设置时需要依据y1范...
ggplot2包中绘制双Y轴折线图主要依靠sec.axis()函数实现,但是这个函数是允许在第一个Y轴基础上建立第二个Y轴,并不是重新建立独立的y轴,而且此函数设置时需要依据y1范围进行相应设置才能画出我们需要的图形: ggplot(df,aes(x=x))+geom_line(aes(y=y1),color="red",size=1)+geom_line(aes(y=y2/3),co...
接下来就是对Y轴操作,添加双坐标轴的代码 ggplot()+theme_bw()+geom_segment(data=df_normal,aes(x=date,y=precip/3-30,xend=date,yend=-30),size=8,colour=gray(0.5))+scale_x_date(date_labels="%b",date_breaks="1 month",expand=c(0.01,0.01),name="",limits=(c(as_date("2020-01-01"...
R语言ggplot2做双Y轴的一些操作 image.png 代码主要来自于链接3 首先是准备数据的代码 library(tidyverse) library(lubridate) #install.packages("devtools") #install.packages("cli") #library(devtools) devtools::install_github("ropensci/weathercan")...
This post describes how to build a dual Y axis chart using R and ggplot2. It uses the sec.axis attribute to add the second Y axis.
# 加载 ggplot2 包library(ggplot2)# 绘制用户平均支出和旅游天数的条形图ggplot(summary_stats,aes(x=name))+geom_bar(aes(y=average_expenditure),stat="identity",fill="blue",alpha=0.6)+geom_bar(aes(y=average_duration*300),stat="identity",fill="red",alpha=0.6)+scale_y_continuous(sec.axis=sec...
ggplot(aes(x=sample,y=rowname)) + geom_tile(aes(fill=exp)) + scale_fill_gradient2(midpoint=2.5, low='#2fa1dd', mid="white", high='#f87669') + scale_y_dendrogram(hclust=yclust) + scale_x_dendrogram(hclust=xclust, position='top') + theme(panel.grid=element_blank(), axis.line...
ggplot(data = df, mapping = aes(x = Day, y = Value)) + sm_boxplot(fill ='black') sm_boxplot Example01 此外,还可以进行修改: ggplot(data = df, mapping = aes(x = Day, y = Value, fill = Day)) + sm_boxplot(shape = 21, point_size = 4, notch ='TRUE', alpha = 0.5) +...