2017-04-27 22:23:09
library(ggplot2) p <- ggplot(diamonds, aes(x=cut, fill=clarity)) + geom_bar(position="dodge") print(p)
library(plotly) ggplotly(p, width=400, height=300)
library(animation) saveGIF({ dev.control("enable") for (col in levels(diamonds$color)){ print(ggplot( diamonds[diamonds$color==col, ], aes(x=cut, fill=clarity) ) + geom_bar(position="dodge") + ggtitle(paste("color:", col))) } }, "diamonds.gif")
ggplotly(p, height=300)
saveGIF
系统要求:
saveLatex
系统要求: (PDF)LaTeXsaveSWF
系统要求: SWF Tools (http://swftools.org)saveVideo
系统要求:
library(readr); library(ggmap) earthquake <- read_csv( "A03_07_interactive_files/files/earthquake.csv" names(earthquake)[c(1, 3, 4, 5, 6)] <- c( "Date", "lat", "long", "Depth", "Grat") earthquake$Year <- as.integer( format(earthquake[["Date"]], "%Y")) earthquake$Grat <- as.numeric( gsub("^M(.+)$", "\\1", earthquake[["Grat"]])) saveGIF({ gg.map <- ggmap(get_googlemap("China", zoom=4)) for (yr in sort(unique(earthquake$Year))){ print(gg.map + geom_point( aes(long, lat, size=Grat, alpha=Depth), data=earthquake[earthquake$Year==yr,], color='red') + scale_alpha(range=c(1, 0.2))+ ggtitle(paste("Earthquake as of", yr))) } }, "earthquake.gif")
R/ |-- <fun>.R inst/ |-- htmlwidgets/ | |-- <pkg>.js | |-- <pkg>.yaml | |-- lib/ | | |-- <lib folder>/ | | | |-- <some>.js | | | |-- plugins/ | | | | |-- <some>.js
devtools::install_github( "madlogos/recharts")
library(recharts) totGDP <- data.table::dcast( ChinaGDP, Prov~., sum, value.var='GDP') ChinaGDP <- ChinaGDP[order(ChinaGDP$Year),] echartr(ChinaGDP, Prov, GDP, Year, type="map_china") %>% setDataRange(splitNumber=0, valueRange=range(totGDP[, 2]), color=c('red','orange','yellow', 'limegreen','green') ) %>% setTheme(width=400, height=400) %>% setTitle("China GDP by Provice, 2012-2014")
library(leaflet) pal <- colorQuantile("YlOrRd", NULL, n = 4) leaflet(quakes[1:100,]) %>% addProviderTiles("Esri.WorldTopoMap") %>% addCircleMarkers(~long, ~lat, popup=~as.character(mag), label=~as.character(mag), color=~pal(mag))
d <- diamonds[sample(nrow(diamonds), 500), ] plot_ly(d, x = d$carat, y = d$price, text = paste("Clarity: ", d$clarity), mode = "markers", color = d$carat, size = d$carat)
library(DT) datatable(iris, options=list(pageLength = 5))
library(wordcloud2) wordcloud2(demoFreq[1:100,], size=0.5)
library(magrittr) library(highcharter) highchart() %>% hc_title( text="Scatter chart with size and color") %>% hc_add_series( mtcars[, c("wt", "mpg","drat", "hp")], type="scatter", mapping=hcaes(wt, mpg, size=drat, color=hp))
library(dygraphs) lungDeaths <- cbind(mdeaths, fdeaths) dygraph(lungDeaths)
edges <- data.frame( from = sample(1:10,8), to = sample(1:10, 8), label = paste("Edge", 1:8), length = c(100,500), width = c(4,1), arrows = c("to", "from", "middle", "middle;to"), dashes = c(TRUE, FALSE), title = paste("Edge", 1:8), smooth = c(FALSE, TRUE), shadow = c(FALSE, TRUE, FALSE, TRUE)) nodes <- data.frame(id = 1:10, group = c("A", "B")) library(visNetwork) visNetwork(nodes, edges)
library(networkD3) data(MisLinks, MisNodes) forceNetwork( Links = MisLinks, Nodes = MisNodes, Source = "source", Target = "target", Value = "value", NodeID = "name", Group = "group", opacity = 0.4)
library(d3heatmap) d3heatmap(mtcars, scale = "column", colors = "Spectral")
library("threejs") library(maps) earth <- paste0("A03_07_interactive_files/", "figure-html/world.topo.bathy.jpg") cities <- world.cities[order(world.cities$pop, decreasing=TRUE)[1:1000],] value <- 100 * cities$pop / max(cities$pop) col <- colorRampPalette(c("red", "gold"))( 10)[floor(10 * value/100) + 1] globejs(img=earth, bg="white", emissive="#aaaacc", lat=cities$lat, long=cities$long, value=value, color=col, atmosphere=TRUE)
library(DiagrammeR) library(magrittr) mermaid(" graph TD A(Rounded)-->B[Rectangular] B-->C{A Rhombus} C-->D[Rectangle One] C-->E[Rectangle Two] ")
library(rbokeh) z <- lm(dist ~ speed, data = cars) p <- figure(width = 400, height = 400) %>% ly_points(cars, hover = cars) %>% ly_lines(lowess(cars), legend = "lowess") %>% ly_abline(z, type = 2, legend = "lm") p
library(rCharts); library(knitr) hair_eye = as.data.frame(HairEyeColor) r1 <- rPlot(Freq ~ Hair | Eye, color = 'Eye', data = hair_eye, type = 'bar') r1$show("iframesrc")
data(economics, package = "ggplot2") econ <- transform(economics, date = as.character(date)) m1 <- mPlot(x = "date", y = c("psavert", "uempmed"), type = "Line", data = econ) m1$set(pointSize = 0, lineWidth = 1) m1$show("iframesrc")
hair_eye_male <- subset(as.data.frame(HairEyeColor), Sex == "Male") n1 <- nPlot(Freq ~ Hair, group = "Eye", data = hair_eye_male, type = "multiBarChart") n1$print(n1$params$dom, include_assets=TRUE)
uspexp <- reshape2::melt(USPersonalExpenditure) x1 <- xPlot(value ~ Var2, group="Var1", data = uspexp, type = "line-dotted") x1$show('iframesrc')
h1 <- hPlot(x = "Wr.Hnd", y = "NW.Hnd", data = MASS::survey, type = c("line", "bubble", "scatter"), group = "Clap", size = "Age") h1$show('iframesrc')
map3 <- Leaflet$new() map3$setView(c(51.505, -0.09), zoom = 13) map3$marker(c(51.5, -0.09), bindPopup = "<p> Hi. I am a popup </p>") map3$marker(c(51.495, -0.083), bindPopup = "<p> Hi. I am another popup </p>") map3$show('iframesrc')
usp <- reshape2::melt(USPersonalExpenditure) usp$Var2 <- as.numeric(as.POSIXct(paste0(usp$Var2, "-01-01"))) p4 <- Rickshaw$new(); p4$layer(value ~ Var2, group = "Var1", data = usp, type = "area") p4$set(slider = TRUE, height = 350); p4$show('iframesrc')
library(maps); library(ggiraph) crimes <- data.frame(state = tolower( rownames(USArrests)), USArrests) states_ <- sprintf("<p>%s</p>", as.character(crimes$state) ) table_ <- paste0("<table><tr><td>UrbanPop</td>", sprintf("<td>%.0f</td>", crimes$UrbanPop), "</tr><tr>", "<td>Assault</td>", sprintf("<td>%.0f</td>", crimes$Assault), "</tr></table>") onclick <- sprintf("window.open(\"%s%s\")", "http://en.wikipedia.org/wiki/", as.character(crimes$state))
crimes$labs <- paste0(states_, table_) crimes$onclick <- onclick states_map <- map_data("state") gg_map <- ggplot(crimes, aes(map_id = state)) + geom_map_interactive(aes( fill = Murder, tooltip = labs, data_id = state, onclick = onclick), map = states_map) + coord_map() + expand_limits(x = states_map$long, y = states_map$lat) ggiraph(code = print(gg_map))
library(ggvis) mtcars %>% ggvis(~wt, ~mpg) %>% layer_points( fill = ~factor(cyl), size := input_slider(100, 1000, value = 100)) %>% layer_smooths(span = input_slider(0.5, 1, value = 1))
library(googleVis) op <- options(gvis.plot.tag='chart') Geo <- gvisGeoChart(Exports, locationvar='Country', colorvar='Profit', options=list(height=300, width=500)) Tbl <- gvisTable(Exports, options=list(height=300, width=200)) plot(gvisMerge(Geo, Tbl, horizontal=TRUE))
|
|
Thank you!