11/14/2019
ggplot2
, tidyr
, tibble
, readr
, purrr
, dplyr
болон бусад багцууд хамаарна.install.packages("tidyverse")
library(tidyverse) library(DT) datatable(iris, fillContainer = FALSE, options = list(pageLength = 5))
Pipe operator %>%
iris %>% group_by(Species) %>% summarise(avg=mean(Sepal.Length))
economics
gecon<-gather(economics,"indicators","values",-date) gecon
econ<-economics %>% filter(date<=as.Date("1970-01-01")) econ
diamonds
diamonds %>% select(starts_with("c"))
diamonds %>% summarise(minimum=min(price),maximum=max(price)) %>% print.data.frame()
## minimum maximum ## 1 326 18823
diamonds %>% group_by(cut)
diamonds %>% mutate(xy=x*y)
df1<-econ %>% select("date","pop") df2<-econ %>% select("unemploy") bind_cols(df1,df2)
Өгөгдлийн хэлбэрийг нь өөрчлөх замаар дараах графикийг дүрслэх боломжтой болно. gecon
өгөгдөлийг IV-р хуудсанд олж авсан билээ.
library(scales) # load package to use comma() my_plot<-ggplot(gecon,aes(x=date,y=values))+ geom_line(color="darkblue")+scale_y_continuous(labels = scales::comma)+ facet_wrap(~indicators, scales = "free", ncol = 3) + labs(x="Date",y="values",title="Economics") # save plot by pdf format in working directory ggsave(plot =my_plot , filename = "my_plot.pdf", width = 25.4, height = 10.73)
my_plot
library(plotly) ggplotly(my_plot) # get interactive plot
head(EuStockMarkets,5)
## DAX SMI CAC FTSE ## [1,] 1628.75 1678.1 1772.8 2443.6 ## [2,] 1613.63 1688.5 1750.5 2460.2 ## [3,] 1606.51 1678.6 1718.0 2448.2 ## [4,] 1621.04 1684.1 1708.1 2470.4 ## [5,] 1618.16 1686.6 1723.1 2484.7
stock<-as.data.frame(EuStockMarkets) %>% gather(index,price) %>% mutate(date=rep(time(EuStockMarkets),4)) attach(stock)
plot_ly(x=date, y=price, color = index, mode= "line")
attach(gecon) plot_ly(x=date ,y=values, color = indicators, mode="line")
library(leaflet) # https://rstudio.github.io/leaflet/ leaflet() %>% addTiles() %>% addMarkers(lng=174.768, lat=-36.852, popup="The birthplace of R")
leaflet() %>% addTiles() %>% addMarkers(lng=106.930831, lat=47.918574, popup="UFE")
R ийн хамгийн том давуу тал нь open source. Иймд маш олон хүн хэрэглэдэг бөгөөд бие биеээсээ асуух бололцоотой.
Michal Siwik
Choisuren Mygmar