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