当还使用AES时,如何使用Custome颜色填充(Viridis)(颜色=变量)

发布于 2025-02-06 09:05:42 字数 381 浏览 0 评论 0原文

我正在尝试使用viridis :: + scale_fill_viridis()实现Viridis软件包。

这是我的代码:

ggplot(combi_plot, aes(x = day_of_symptoms, y = ct_value)) + geom_smooth(aes(colour=gender)) + 
xlim(-5,20)  + scale_fill_viridis()

但是,这可能会干扰我使用AES(颜色=性别),它使用GGPLOT2 BASIC PALET的2种不同颜色为我的数据集中的两个性别绘制了单独的线条。

我的问题是: 您如何使用自定义的调色板(例如Viridis)与AES(颜色=“变量”)参数结合使用。

干杯

I am trying to implement the viridis package using viridis:: + scale_fill_viridis().

This is my code:

ggplot(combi_plot, aes(x = day_of_symptoms, y = ct_value)) + geom_smooth(aes(colour=gender)) + 
xlim(-5,20)  + scale_fill_viridis()

However, this probably interferes with my use of aes(colour=gender), which draws a seperate line for the two genders in my dataset, using 2 different colours of the ggplot2 basic palet.

My question is:
How do you use a custom color palette such as viridis, in combination with the aes(colour="variable") argument.

Cheers

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

等数载,海棠开 2025-02-13 09:05:42

因此,没有您的数据,很难做到这一点。我也不完全确定您要着色。我假设这是性别。

我设置了一个调色板(我喜欢wespalette,所以这里是一个wespalette示例,但是您可以使用Virdis做同样的事情,获得​​要使用的特定颜色的向量)。

    # load color palette
palette_c <- wes_palette("FantasticFox1", 5)

然后,我掏出要使用的颜色。您可能想尝试嵌入功能。

#Add colors
      + scale_color_manual(values = c("Female" = palette_c[5], "Male" = palette_c[4]))

另外,可能必须将颜色移至AES之外,但我不确定您的数据结构是什么,因此您的里程可能会有所不同。因此,有可能开始修补类似的东西:

ggplot(combi_plot, aes(x = day_of_symptoms, y = ct_value)) + geom_smooth(color=gender) + 
xlim(-5,20) + scale_color_manual(values = c("Female" = palette_c[5], "Male" = palette_c[4]))

So, it's a little difficult to do this without your data. I'm also not entirely sure what, specifically, you're trying to color. I'm assuming it's the gender.

I set a color palette (I like wespalette, so here's a wespalette example, but you could do the same with virdis, getting a vector of specific colors you want to use).

    # load color palette
palette_c <- wes_palette("FantasticFox1", 5)

Then, I pull out the colors I want to use. Rather than the scale_..._virdis, you might want to try the built in functions.

#Add colors
      + scale_color_manual(values = c("Female" = palette_c[5], "Male" = palette_c[4]))

Also, might have to move the color outside of the aes, but I'm not sure what the structure of your data is, so your mileage may vary. So, potentially start tinkering with something like:

ggplot(combi_plot, aes(x = day_of_symptoms, y = ct_value)) + geom_smooth(color=gender) + 
xlim(-5,20) + scale_color_manual(values = c("Female" = palette_c[5], "Male" = palette_c[4]))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文