mtc*_*lot 5 plot r linechart plotly r-plotly
我需要绘制一条路径,该路径并不严格从左到右,而是在 y 轴上交叉,但是自从我升级到plotly 4.7以来,我不能不这样做。fx 没问题。3.6
有谁知道如何以情节方式告诉路径如何排序?
library(dplyr)
library(plotly) # > 4.x
data.frame(x = c(1:5,5:1),y = c(1:10)) %>%
arrange(y) %>%
plot_ly(x = ~x,y = ~y) %>% add_lines()
Run Code Online (Sandbox Code Playgroud)
如果你查看 data.frame 它应该遵循红色路径:
data.frame(x = c(1:5,5:1),y = c(1:10)) %>% arrange(y)
x y
1 1 1
2 2 2
3 3 3
4 4 4
5 5 5
6 5 6
7 4 7
8 3 8
9 2 9
10 1 10
Run Code Online (Sandbox Code Playgroud)
您可以在以下位置设置模式plotly
:
data.frame(x = c(1:5,5:1),y = c(1:10)) %>%
arrange(y) %>%
plot_ly(x = ~x,y = ~y, mode = 'lines+markers')
Run Code Online (Sandbox Code Playgroud)
图表将是:
或者您可以使用以下 base-R 解决方案:
df <- data.frame(x = c(1:5,5:1),y = c(1:10))
with(df, plot(x,y))
with(df, lines(x,y))
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
759 次 |
最近记录: |