在 Plotly 和 R 中以红色显示底片 [英] Show negatives in Red in Plotly and R

查看:76
本文介绍了在 Plotly 和 R 中以红色显示底片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将底片显示为红色

试图在网上寻找解决方案,但没有找到

Tried to look for solutions online but none found

plot_ly(x = ecomm_yoy2$YOY, y = ecomm_yoy2$Brand, type = 'bar', orientation = 'h') %>%
  layout(xaxis = list(title = "% YOY change in £ for June", dtick = 10)) %>% 
  layout(yaxis = list(categoryorder = "array", categoryarray = ecomm_yoy2$YOY)) %>%
  add_annotations(text = ecomm_yoy2$YOY, showarrow = F, xshift = 25)

目前只显示蓝色

推荐答案

以下是使用 plotly 的 colorcolors 参数的可能解决方案:

Here is a possible solution using plotly's color and colors arguments:

ecomm_yoy2 <- data.frame(YOY = -19:20, Brand = 1:40)

plot_ly(ecomm_yoy2, x = ~YOY, y = ~Brand, type = 'bar', orientation = 'h', color = ~YOY < 0, colors = c("chartreuse3", "red"), name = ~ifelse(YOY < 0, "< 0", ">= 0")) %>%
  layout(xaxis = list(title = "% YOY change in £ for June", dtick = 10)) %>% 
  layout(yaxis = list(categoryorder = "array", categoryarray = ~YOY)) %>%
  add_annotations(text = ~YOY, showarrow = F, xshift = 25)

您可能想看看:

library(plotly)
library(listviewer)
schema(jsonedit = interactive())

让您可以浏览 plotly 的可用轨迹及其参数.

which let's you navigate through plotly's available traces and their arguments.

这篇关于在 Plotly 和 R 中以红色显示底片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆