filmov
tv
plotly Line Plot in R (Example) | Draw an Interactive Curve Chart | Color, Type & Overlaid Points

Показать описание
R code of this video:
VarA = c(15,20,25,18),
VarB = c(22,24,26,28),
VarC = c(5,10,20,40))
df_long <- df_wide %>% tidyr::pivot_longer(cols = c(VarA, VarB,VarC))
library(plotly)
plot_ly(
data = df_wide,
x = ~date,
y = ~VarA,
type = "scatter",
mode = "lines"
)
plot_ly(
data = df_wide,
x = ~date,
y = ~VarA,
name = "VarA",
type = "scatter",
mode = "lines"
) %>%
add_trace(y = ~VarB, name = "VarB")%>%
add_trace(y = ~VarC, name = "VarC")
plot_ly(
data = df_long,
x = ~date,
y = ~value,
color = ~name,
type = "scatter",
mode = "lines"
)
plot_ly(
data = df_long,
x = ~date,
y = ~value,
color = ~name,
type = "scatter",
mode = "lines+markers"
)
plot_ly(
data = df_long,
x = ~date,
y = ~value,
color = ~name,
type = "scatter",
mode = "lines+markers",
line = list(width = 4)
)
plot_ly(
data = df_long,
x = ~date,
y = ~value,
color = ~name,
type = "scatter",
mode = "lines+markers",
line = list(width = 4, dash = "dot")
)
plot_ly(
data = df_wide,
x = ~date,
y = ~VarA,
name = "VarA",
type = "scatter",
mode = "lines",
line = list(width = 2,
dash = "solid",
color = "green")) %>%
add_trace(y = ~VarB, name = "VarB", mode = "lines", line = list(width = 4, dash = "dash", color = "gray"))%>%
add_trace(y = ~VarC, name = "VarC", mode = "lines+markers", line = list(dash = "dot", color = "red"))
plot_ly(
data = df_long,
x = ~date,
y = ~value,
color = ~name,
type = "scatter",
mode = "lines+markers",
line = list(width = 4, dash = "dot")) %>%
layout(hovermode = "x unified")
Follow me on Social Media:
Комментарии