基于echarts4r中的变量添加彩色点
我在Echarts4r中使用了一些e_lines完成了一个烛台图。我想在一些蜡烛中添加一些基于变量(“点”)颜色的点。
这是代码
library(quantmod)
library(echarts4r)
library(magrittr)
GS |>
e_charts(date) |>
e_candle(GS.Open, GS.Close, GS.Low, GS.High, name = "Goldman Sachs",
lineStyle = list(
color = "#42eff5", # bull
color0 = "#f54242", # bear
borderColor = NA,
borderColor0 = NA)) |>
e_datazoom(type = "slider") |>
e_title("Candlestick chart", "Quantmod data") |>
e_line(serie = level, name = "Fib", lineStyle = list(color = "green", opacity = 0.8, type = "dotted"), legend = T) %>%
e_line(serie = level2, name = "Fib", lineStyle = list(color = "blue", opacity = 0.8, type = "dotted"), legend = T) %>%
# e_scatter(serie = GS.Close, name = "Signal", symbol_size = 10) %>%
# e_visual_map(serie = points) %>%
e_datazoom(type = "slider") %>%
e_tooltip(trigger = "axis")
一切都很好的代码,直到我添加 e_visual_map
的点颜色:
问题是:
- 受
e_visual_map
- 蜡烛的颜色
影响
GS <- structure(list(GS.Open = c(200.600006, 200.220001, 198.429993,
199.050003, 203.539993, 203.399994, 208.339996, 210.899994, 210.850006,
212.199997, 213.75), GS.High = c(203.320007, 200.669998, 200,
203.949997, 204.899994, 208.440002, 213.169998, 214.220001, 215.130005,
214.089996, 214.809998), GS.Low = c(197.820007, 198.070007, 197.899994,
198.100006, 202, 201.5, 207.600006, 210.399994, 210.850006, 210.850006,
209.100006), GS.Close = c(200.720001, 198.850006, 199.050003,
203.729996, 204.080002, 208.110001, 211.880005, 213.990005, 213.589996,
213.229996, 209.679993), GS.Volume = c(6494900, 6460200, 5892900,
7851000, 7147100, 8025700, 9039400, 6618900, 5846600, 5306300,
6423200), GS.Adjusted = c(162.160843, 160.65007, 160.811646,
164.59259, 164.875336, 168.131134, 171.177002, 172.881592, 172.558426,
172.267532, 169.399551), date = c("2007-01-03", "2007-01-04",
"2007-01-05", "2007-01-08", "2007-01-09", "2007-01-10", "2007-01-11",
"2007-01-12", "2007-01-16", "2007-01-17", "2007-01-18"), level = c(200,
200, 200, 200, 200, 200, 200, 200, 200, 200, 200), level2 = c(250,
250, 250, 250, 250, 250, 250, 250, 250, 250, 250), points = -5:5), row.names = c("2007-01-03",
"2007-01-04", "2007-01-05", "2007-01-08", "2007-01-09", "2007-01-10",
"2007-01-11", "2007-01-12", "2007-01-16", "2007-01-17", "2007-01-18"
), class = "data.frame")
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用
group_by
向每个“点”值添加随机颜色。当您添加新蜡烛时,由于group_by
,它将获得相同的颜色。这是一个可重现的示例:用
创建/strong>
在这里a
viridis
选项:使用 e_add_nested 带有“ itemStyle”之后的
e_scatter
调用。确保您的列有颜色以表示要点。我使用了Rainbow
颜色,但是您可以将它们更改为您想要的任何东西。这是一个可重复的示例:在2022-09-10创建的 reprex v2。 0.2
如您所见,每个点都基于您的“点”列具有不同的颜色。
You could add a random color to each "points" value using
group_by
. When you add a new candle, it will get the same color because ofgroup_by
. Here is a reproducible example:Created on 2022-09-10 with reprex v2.0.2
Viridis
Here a
viridis
option:Created on 2022-09-10 with reprex v2.0.2
You could use the function
e_add_nested
with "itemstyle" after youre_scatter
call. Make sure you have a column with the colors to represent the points. I used therainbow
colors, but you can change them to whatever you want. Here is a reproducible example:Created on 2022-09-10 with reprex v2.0.2
As you can see, each point has a different color based on your "points" column.