some examples in r- [data visualization--r graphics]
Post on 16-Apr-2017
78 Views
Preview:
TRANSCRIPT
Some Examples in R- [Data Visualization--R graphics]
Rchartsand others..library(rpart.plot),library(rCharts),library(plyr),library(knitr),library(reshape2),library(scales)
Reference:
https://github.com/ramnathv/rCharts/tree/master/inst/libraries
http://www.rpubs.com/dnchari/rcharts
rCharts package by Ramnath Vaidyanathan
Prepared by Volkan OBAN
CODES:
require(rCharts) ## Example 1
names(iris) = gsub("\\.", "", names(iris))
rPlot(SepalLength ~ SepalWidth | Species, data = iris, color = 'Species', type = 'point')
Example2-
## Example 2 Facetted Barplot
hair_eye = as.data.frame(HairEyeColor)
rPlot(Freq ~ Hair | Eye, color = 'Eye', data = hair_eye, type = 'bar')
Example3-
require(rCharts)
> names(iris) = gsub("\\.", "", names(iris))> rPlot(SepalLength ~ SepalWidth | Species, data = iris, color = 'Species', type = 'point')> ## Example 2 Facetted Barplot> hair_eye = as.data.frame(HairEyeColor)> rPlot(Freq ~ Hair | Eye, color = 'Eye', data = hair_eye, type = 'bar')> hair_eye = as.data.frame(HairEyeColor)> p2 <- nPlot(Freq ~ Hair, group = 'Eye',+ data = subset(hair_eye, Sex == "Female"),+ type = 'multiBarChart'+ )> p2$chart(color = c('brown', 'blue', '#594c26', 'green'))> p2
Example 4:
p <- nPlot(~ cyl, data = mtcars, type = 'pieChart')> p$chart(donut = TRUE> p5
Example 5:
data(economics, package = 'ggplot2')> p <- nPlot(uempmed ~ date, data = economics, type = 'lineChart')> p
Example 6:
dat <- data.frame(
t = rep(0:23, each = 4),
var = rep(LETTERS[1:4], 4),
val = round(runif(4*24,0,50)) )
p<- nPlot(val ~ t, group = 'var', data = dat, type = 'stackedAreaChart', id = 'chart' )
p
Example 7:
require(rCharts)> p1 <- rPlot(SOG ~ yearID, data = team_data,+ type = "point",+ size = list(const = 2),+ color = list(const = "#888"),+ tooltip = "#! function(item){+ return item.SOG + ' ' + item.name + ' ' + item.yearID+ } !#"+ )> p1
> myteam = "Boston Red Sox"> p1$layer(data = team_data[team_data$name == myteam,],+ color = list(const = 'red'),+ copy_layer = T)> p1$set(dom = 'chart3')> p1>
Example 8:
> > library(rCharts)> library(plyr)> library(knitr)> library(reshape2)> library(scales)> options(RCHART_WIDTH = 600, RCHART_HEIGHT = 400)> knitr::opts_chunk$set(comment = NA, results = 'asis', tidy = F, message = F)> data(tips, package = 'reshape2')
p= rPlot(x = 'day', y = 'box(tip)', data = tips, type = 'box')> p
nba = read.csv('http://datasets.flowingdata.com/ppg2008.csv')> nba.m = ddply(melt(nba), .(variable), transform, rescale = rescale(value))> p= rPlot(Name ~ variable, color = 'rescale', data = nba.m, type = 'tile', height = 600)> p
Example:
haireye = as.data.frame(HairEyeColor)> dat = subset(haireye, Sex == "Female" & Eye == "Blue")> haireye = as.data.frame(HairEyeColor)> dat = subset(haireye, Sex == "Female" & Eye == "Blue")> p1 = mPlot(x = 'Hair', y = list('Freq'), data = dat, type = 'Bar', labels = list("Count"))> p1
dat = subset(haireye, Sex == "Female")
p2 = mPlot(Freq ~ Eye, group = "Hair", data = dat, type = "Bar", labels = 1:4)
p2
Example:
data(economics, package = 'ggplot2')
dat = transform(economics, date = as.character(date))
p3 <- mPlot(x = "date", y = list("psavert", "uempmed"), data = dat, type = 'Line',
pointSize = 0, lineWidth = 1)
p3$set(xLabelFormat = "#! function (x) {
return x.toString(); }
!#")
p3$set(type = 'Area')
p3
Example: ecm = reshape2::melt(economics[,c('date', 'uempmed', 'psavert')], id = 'date')
p7 = nPlot(value ~ date, group = 'variable', data = ecm, type = 'lineWithFocusChart')
p7$xAxis( tickFormat="#!function(d) {return d3.time.format('%b %Y')(new Date( d * 86400000 ));}!#" )
p7
Example:
library(rpart.plot)h= hPlot(x = "Wr.Hnd", y = "NW.Hnd", data = MASS::survey, + type = c("line", "bubble", "scatter"), group = "Clap", size = "Age")h> map3 = Leaflet$new()> map3$setView(c(41.7627, -72.6743), zoom = 13)> map3$marker(c(41.7627, -72.6743), bindPopup = "<p> Hi. I am a popup </p>")> map3$marker(c(41.70, -72.60), bindPopup = "<p> Hi. I am another popup </p>")> map3> map3 = Leaflet$new()> map3$setView(c(41.7627, -72.6743), zoom = 13)> map3$marker(c(41.7627, -72.6743), bindPopup = "<p> Hi. I am a popup </p>")> map3$marker(c(41.70, -72.60), bindPopup = "<p> Hi. I am another popup </p>")> map3Example:
> map3 = Leaflet$new()> map3$setView(c(41.7627, -72.6743), zoom = 13)> map3$marker(c(41.7627, -72.6743), bindPopup = "<p> Hi. I am a popup </p>")> map3$marker(c(41.70, -72.60), bindPopup = "<p> Hi. I am another popup </p>")> map3
Reference:
https://github.com/ramnathv/rCharts/tree/master/inst/libraries
http://www.rpubs.com/dnchari/rcharts
rCharts package by Ramnath Vaidyanathan
top related