简体   繁体   English

R ggplot viridis 改变颜色渐变

[英]R ggplot viridis change the color gradient

Hello I am plotting scatter plot using R ggplot for coloring using virdis, I wanted split the color legend to get more contrast between ranges currently legend having 1000,2000,3000,4000 In between this split this to get more color currently my code looking as below您好,我正在使用 R ggplot 绘制散点图 plot 以使用 virdis 进行着色,我想拆分颜色图例以在当前图例具有 1000,2000,3000,4000 的范围之间获得更大的对比度,目前我的代码看起来像以下

library(dplyr)
library(ggplot2)
library("viridis")

df <- tibble(gene   = sample.int(5000),aceth  = rnorm(5000),acvitd = rnorm(5000))
df$log_mean=log(df$gene)
p=ggplot(df, aes(aceth, acvitd))+
  geom_point(aes(color =gene)) +
  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"))

p=p+ theme(legend.position = "top") +
     scale_color_viridis(option = "A",
     name = "mean",
     guide = guide_colourbar(direction = "horizontal",
     barheight = unit(4, units = "mm"),
     barwidth = unit(100, units = "mm"),
     draw.ulim = F,
     title.hjust = 0.5,
     label.hjust = 0.5, title.position = "top"))

How I wanted my graph look like我希望我的图表看起来如何

在此处输入图像描述

can anyone suggest me谁能建议我

Perhaps you're looking for scale_colour_vridis_b to bin your colours?也许您正在寻找scale_colour_vridis_b来分类您的颜色?

df <- tibble(gene   = sample.int(5000),aceth  = rnorm(5000),acvitd = rnorm(5000))
df$log_mean=log(df$gene)
p=ggplot(df, aes(aceth, acvitd))+
  geom_point(aes(color = - (aceth + acvitd))) +
  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"))

p+ theme(legend.position = "top") +
     scale_colour_viridis_b(option = "A", values = 0:10 /10, breaks = 0:5 - 2.5)

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM