Rshiny如何做出折线图

最简单的hello shiny做出的是条形图,修改哪里,改成什么能将条形图转换成折线图?

img

在R Shiny中创建折线图需要使用plotly或ggplot2包中的函数。下面是使用这两个包创建折线图的示例:
使用plotly包创建折线图:


```r

library(plotly)
 
# 创建数据
data <- data.frame(
  x = c(1, 2, 3, 4, 5),
  y = c(10, 20, 15, 25, 30)
)
 
# 创建plotly对象
plot <- plot_ly(data, x = ~x, y = ~y, type = 'scatter', mode = 'lines')
 
# 输出plotly对象
plot


使用ggplot2包创建折线图:

library(ggplot2)
 
# 创建数据
data <- data.frame(
  x = c(1, 2, 3, 4, 5),
  y = c(10, 20, 15, 25, 30)
)
 
# 创建ggplot对象
plot <- ggplot(data, aes(x = x, y = y)) + 
  geom_line()
 
# 输出ggplot对象
plot


```