您好,我正在使用 ggplot 绘制两个图表,用于发送两个不同的数据并使用 viridis 颜色渐变。由于数据,两个图形颜色渐变不同,所以我想让它相同,任何人都可以建议我
数据
https://drive.google.com/file/d/1HUbEQMjIS3ybYuKUaVXT9M_f4ZR-BQXt/view?usp=sharing
编码我使用的内容
library("viridis")
df=read.table("test.txt",sep='\t', header=TRUE)
df = data.frame(df)
#first data
df$log_mean=log(df$data1)
df$data3=log2(df$data3)
df$data2=log2(df$data2)
#second data
df$log_mean2=log(df$df1)
df$df3=log2(df$df3)
df$df2=log2(df$df2)
#plot1
p1=ggplot(df, aes(data3,data2),pch=19,cex=1.9)+
geom_point(aes(color =log_mean)) +
theme(legend.position = "top")+
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
panel.background = element_blank(), axis.line = element_line(colour = "black"))+
theme(text = element_text(size = 20, face="bold"))
#plot2
p2=ggplot(df, aes(df3,df2),pch=19,cex=1.9)+
geom_point(aes(color =log_mean2)) +
theme(legend.position = "top")+
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
panel.background = element_blank(), axis.line = element_line(colour = "black"))+
theme(text = element_text(size = 20, face="bold"))
#viridis color
p1+scale_color_viridis(option = "C")
p2+scale_color_viridis(option = "C")