R 通过图表增加数据价值

R自带的数据集,在RStudio运行复习下相关的操作

  • ggplot2

  • dygraphs

  • plotly

 

高质量图表进行ggplot2

 

# Load visualisation packages & datasets
library(ggplot2)
library(colorspace)
library(datasets)
head(iris)

#Scatter plot with clusters
spc<-ggplot(iris, aes(Petal.Length, Petal.Width, color = Species)) + geom_point()
spc
# line plot
lpc<-ggplot(iris, aes(x=Petal.Width, y=Petal.Length, group=Species)) +
  geom_line(aes(color=Species))+
  geom_point(aes(color=Species))
lpc

dygraphs更加优雅一些

# Data management packages in R
library(zoo)
library(xts)
# dygraphs in R
library(dygraphs)
# Generate dataset 
value<-sample(100:800,100,replace = T)
time<-seq(from=Sys.time(),to=Sys.time()+60*60*24*99,by="day")
data<-data.frame(time=time,value=value)

# dygraph lineplot
dygraph(dy_data)

# dygraph stepplot
dygraph(dy_data)  %>% dyOptions(colors="red", pointSize = 2,drawGrid =T,stepPlot = T) %>% dyRangeSelector()

交互的情况 --->>>> plotly

 

#plotly graphs
library(plotly)
# Data management packages in R
library(zoo)
library(xts)
# Generate dataset 
value<-sample(100:800,100,replace = T)
time<-seq(from=Sys.time(),to=Sys.time()+60*60*24*99,by="day")
data<-data.frame(time=time,value=value)

#plotly lineplot
lp % add_trace(y = value,mode = 'lines')%>% 
layout(title = "Generated dataset",
       xaxis = list(title = "Months"),
       yaxis = list (title = "Values"))
lp


#plotly line marker plot
lm% add_trace(y = value,mode = 'lines+markers')%>%  
layout(title = "Generated dataset",
       xaxis = list(title = "Months"),
       yaxis = list (title = "Values"))
lm

#plotly marker plot
m% add_trace(y = value,mode = 'markers')%>%  
  layout(title = "Generated dataset",
         xaxis = list(title = "Months"),
         yaxis = list (title = "Values"))
m

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值