0

您好,我正在使用 R ggplot 绘制散点图以使用 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"))

我希望我的图表看起来如何

在此处输入图像描述

谁能建议我

4

1 回答 1

0

也许您正在寻找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)

在此处输入图像描述

于 2020-08-07T12:51:23.533 回答