本篇參考 Use the Javascript features for your R charts
install.packages("devtools")
library(devtools)
install.packages("rAmCharts")
devtools::install_github("datastorm-open/rAmCharts")
setwd("/media/hsusir/DATA/Rdata Practice/03Visualization/rAmcharts")
library(datasets)
library(rAmCharts)
## Important changes: constructors legend() and title() have been replaced by amLegend() and amTitle().
## For any bug report or feed back see https://github.com/datastorm-open/rAmCharts
[Barplot]
data(data_gbar)
head(data_gbar)
## year day month income expenses
## 1 2005 01/06/2005 06/2005 23.5 18.1
## 2 2006 02/06/2005 07/2005 26.2 22.8
## 3 2007 03/06/2005 08/2005 30.1 23.9
## 4 2008 04/06/2005 09/2005 29.5 25.1
## 5 2009 05/06/2005 10/2005 24.6 25.0
data(data_bar)
amBarplot(x = "country", y = "visits", data = data_bar,
labelRotation = -45)
amBarplot(x = "country", y = "visits", data = data_bar, horiz = TRUE)#Horizontal bar
amBarplot(x = "country", y = "visits", data = data_bar, show_values = TRUE, labelRotation = -90)#Display values
amBarplot(x = "year", y = c("income", "expenses"), data = data_gbar)#Grouped columns
#Parse dates - default label: first day of each year
pipeR::pipeline(
amBarplot(x = "year", y = c("income", "expenses"), data = data_gbar,
dataDateFormat = "YYYY", minPeriod = "YYYY"),
setChartCursor()
)
#Parse dates - default label: first day of each month
pipeR::pipeline(
amBarplot(x = "month", y = c("income", "expenses"), data = data_gbar,
dataDateFormat = "MM/YYYY", minPeriod = "MM"),
setChartCursor()
)
#Change groups colors
amBarplot(x = "year", y = c("income", "expenses"), data = data_gbar,
groups_color = c("#87cefa", "#c7158"))
amBarplot(x = "year", y = c("income", "expenses"), data = data_gbar, stack_type = "regular")#Stacked bars
amBarplot(x = "year", y = c("income", "expenses"), data = data_gbar, stack_type = "100")#100% Stacked bars
amBarplot(x = "year", y = c("income", "expenses"), data = data_gbar, layered = TRUE)#Layered bars
#Data with row names
dataset <- data.frame(get(x = "USArrests", pos = "package:datasets"))
amBarplot(y = c("Murder", "Assault", "UrbanPop", "Rape"), data = dataset, stack_type = "regular")
amBarplot(x = "year", y = c("income", "expenses"), data = data_gbar, legend = TRUE)#legend
amBarplot(x = "year", y = c("income", "expenses"), data = data_gbar, legend = TRUE, legendPosition = "left")#legendPosition
amBarplot(x = "country", y = "visits", data = data_bar, labelRotation = -45, export = TRUE)#export
amBarplot(x = "country", y = "visits", data = data_bar, labelRotation = -45, export = TRUE,
exportFormat = "JPG") #exportFormat
amBarplot(x = "country", y = "visits", data = data_bar, labelRotation = -45, main = "My Barchart",
mainColor = "#68838B", mainSize = 25, creditsPosition = "top-right")#main and creditsPosition
[Boxplot]
dataset <- get(x = "ChickWeight", pos = "package:datasets")
amBoxplot(weight~Diet, data=dataset)
amBoxplot(weight~Diet, data=dataset, horiz = TRUE)#Horizontal boxplot
amBoxplot(weight~Diet, data=dataset, xlab = "diet", ylab = "weight")#Naming axis
amBoxplot(weight~Diet, data=dataset, col = "#CD1076")#Change color
#main and creditsPosition
amBoxplot(weight~Diet, data=dataset, labelRotation = -45, main = "My Barchart",
mainColor = "#68838B", mainSize = 25, creditsPosition = "top-right")
[histogram]
data_hist <- get(x = "iris", pos = "package:datasets")$Sepal.Length
head(data_hist)
## [1] 5.1 4.9 4.7 4.6 5.0 5.4
amHist(x = data_hist)
amHist(x = data_hist, border = "#CECECE")
amHist(x = data_hist, xlab = "xlab", ylab = "ylab")
amHist(x = data_hist, ylim = c(0,.8), freq = FALSE)#Set ylim
amHist(x = data_hist, export = TRUE, exportFormat = "JPG")#exportFormat
#main and creditsPosition
amHist(x = data_hist, main = "My Histogram",
mainColor = "#68838B", mainSize = 25, creditsPosition = "top-right")
[Pie]
data("data_pie")
head(data_pie)
## label value
## 1 Facebook 38
## 2 Twitter 25
## 3 LinkedIn 15
## 4 Google+ 14
## 5 Pinterest 8
amPie(data = data_pie)
amPie(data = data_pie, depth = 10)#3D pie
amPie(data = data_pie, inner_radius = 50)#Donut chart
amPie(data = data_pie, legend = TRUE)#legend
amPie(data = data_pie, legend = TRUE, legendPosition = "left")#legendPosition
amPie(data = data_pie, export = TRUE)#export
amPie(data = data_pie, export = TRUE, exportFormat = "JPG")
#main and creditsPosition
amPie(data = data_pie, main = "My Pie",
mainColor = "#68838B", mainSize = 25, creditsPosition = "bottom-right")
[Radar]
data <- data.frame(label = c("A", "Z", "E", "R", "T"),
Product1 = c(1, 2, 3, 4, 2),
Product2 = c(2, 8, 1, 1, 0),
Product3 = c(1,1,2,2,4))
amRadar(data = data)
amRadar(data = data, col = c("#0000FF", "#00FF00", "#FF0000"))#Change color
amRadar(data = data, backTransparency = 1)#backTransparency
amRadar(data = data, backTransparency = c(0, 0.4, 0.6))
amRadar(data = data, type = "circles")#type
amRadar(data = data, pch = "bubble", backTransparency = 0, legend = TRUE)#legend
amRadar(data = data, pch = "bubble", backTransparency = 0, legend = TRUE,
legendPosition = "left")#legendPosition
amRadar(data = data, pch = "bubble", backTransparency = 0, export = TRUE)#export
amRadar(data = data, pch = "bubble", backTransparency = 0, export = TRUE, exportFormat = "JPG")
#main and creditsPosition
amRadar(data = data, pch = "bubble", backTransparency = 0, main = "My Radar",
mainColor = "#68838B", mainSize = 25, creditsPosition = "bottom-right")