简体   繁体   English

R图中配色方案的最大观测值

[英]R maximum observations for color scheme in a plot

I am working with a relatively large dataset (n>1000). 我正在使用相对较大的数据集(n> 1000)。 I have come across a problem when applying "ifelse" in order to specify different colors in a plot. 应用“ ifelse”以在绘图中指定不同颜色时遇到了一个问题。

With a small selection of data, the specified colors are displayed. 只需少量选择数据,即可显示指定的颜色。 When using the large dataset, the colors appear as red and green, no matter which colors I specified. 使用大型数据集时,无论我指定哪种颜色,颜色都将显示为红色和绿色。 So far I have encountered this problem with ggplot2, plotly and condformat (with different data). 到目前为止,我在ggplot2,plotly和condformat(使用不同数据)中遇到了此问题。

Eg 例如

condformat(fullData[1:500,]) %>%
rule_fill_discrete(title, expression = ifelse(start_var == end_var,  "purple", "orange"))

works, but 可行,但是

condformat(fullData[1:1000,]) %>%
rule_fill_discrete(title, expression = ifelse(start_var == end_var, "purple", "orange"))

will display the colors not in orange and purple, but red and green. 将显示的颜色不是橙色和紫色,而是红色和绿色。

I apologize in advance if this is a trivial question, but my google search remained unsuccesful. 如果这是一个琐碎的问题,我事先表示歉意,但我的Google搜索仍然失败。 Thank you in advance! 先感谢您!

rule_fill_discrete maps discrete values to colors. rule_fill_discrete将离散值映射到颜色。 If you want to specify which colors are mapped to which values you should use a named vector as the colours argument. 如果要指定将哪些颜色映射到哪些值,则应使用命名向量作为colours参数。 See this example: 请参阅以下示例:

library(condformat)
d <- data.frame(title = c("Monday", "Tuesday", "Wednesday"),
                start_var = c(4, 5, 6),
                end_var = c(4, 8, 6))
condformat(d) %>%
  rule_fill_discrete(title,
                     expression = start_var == end_var,
                     colours = c(`TRUE` = "purple", `FALSE` = "orange"))

运行给定代码的结果

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

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