All examples are from blog
library(d3radarR)
json_data = jsonlite::fromJSON(
'
[
{
"key":"Nokia Smartphone",
"values":[
{ "axis":"Battery Life", "value":0.26 }, { "axis":"Brand", "value":0.10 },
{ "axis":"Contract Cost", "value":0.30 }, { "axis":"Design And Quality", "value":0.14 },
{ "axis":"Have Internet Connectivity", "value":0.22 }, { "axis":"Large Screen", "value":0.04 },
{ "axis":"Price Of Device", "value":0.41 }, { "axis":"To Be A Smartphone", "value":0.30 }
]
},
{
"key":"Samsung",
"values":[
{ "axis":"Battery Life", "value":0.27 }, { "axis":"Brand", "value":0.16 },
{ "axis":"Contract Cost", "value":0.35 }, { "axis":"Design And Quality", "value":0.13 },
{ "axis":"Have Internet Connectivity", "value":0.20 }, { "axis":"Large Screen", "value":0.13 },
{ "axis":"Price Of Device", "value":0.35 }, { "axis":"To Be A Smartphone", "value":0.38 }
]
},
{
"key":"iPhone",
"values":[
{ "axis":"Battery Life", "value":0.22 }, { "axis":"Brand", "value":0.28 },
{ "axis":"Contract Cost", "value":0.29 }, { "axis":"Design And Quality", "value":0.17 },
{ "axis":"Have Internet Connectivity", "value":0.22 }, { "axis":"Large Screen", "value":0.02 },
{ "axis":"Price Of Device", "value":0.21 }, { "axis":"To Be A Smartphone", "value":0.50 }
]
}
]
',
simplifyDataFrame = FALSE
)
d3radar(json_data)
library(d3radarR)
library(scales)
library(dplyr)
library(purrr)
mtcars %>%
add_rownames( var = "key" ) %>%
mutate_each(funs(rescale), -key) %>%
#limit to 8 rows for manageability
head(8) %>%
by_row(
function(row){
list(
key = row[["key"]],
values = lapply(
names(row)[-match("key",names(row))],
function(nm){
list(
"axis" = nm,
"value" = row[[nm]]
)
}
)
)
}
) %>%
{
d3radar( .$.out )
}
library(d3radarR)
espn_efficiency <- list(
list(
key = "Alabama",
values = list(
list(axis = "offense", value = 70.9/100),
list(axis = "defense", value = 92.9/100),
list(axis = "specialtms", value = 58.3/100)
)
),
list(
key = "Oklahoma",
values = list(
list(axis = "offense", value = 83.3/100),
list(axis = "defense", value = 83.1/100),
list(axis = "specialtms", value =42.6/100)
)
),
list(
key = "Clemson",
values = list(
list(axis = "offense", value = 81.3/100),
list(axis = "defense", value = 87.1/100),
list(axis = "specialtms", value = 32.4/100)
)
),
list(
key = "Michigan State",
values = list(
list(axis = "offense", value = 70.5/100),
list(axis = "defense", value = 73.2/100),
list(axis = "specialtms", value = 39.0/100)
)
)
)
d3radar( espn_efficiency )
library(plotly)
d <- structure(list(Year = c("2015", "2015", "2015", "2015", "2015","2015",
"2015", "2015", "2015", "2015", "2015","2015",
"2015", "2015", "2015", "2015", "2015", "2015",
"2015", "2015", "2015", "2015", "2015", "2015",
"2016", "2016", "2016", "2016", "2016", "2016",
"2016", "2016", "2016", "2016", "2016", "2016",
"2016", "2016", "2016", "2016", "2016", "2016",
"2016", "2016", "2016", "2016", "2016", "2016"),
Response = structure(c(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L,
11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L,
19L, 20L, 21L, 22L, 23L, 24L, 1L, 2L, 3L,
4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L,
14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L,
23L, 24L),
.Label = c("Trustworthy","Supportive","Leading", "Strong", "Dependable",
"Consultative", "Knowledgeable",
"Sensible", "Intelligent",
"Consistent", "Stable", "Innovative",
"Aggressive","Conservative",
"Visionary", "Arrogant",
"Professional", "Responsive",
"Confident", "Accessible",
"Timely", "Focused", "Niche",
"None"),
class = "factor"),
Proportion = c(0.54, 0.48, 0.33, 0.35,0.47, 0.3, 0.43, 0.29, 0.36,
0.38, 0.45, 0.32, 0.27, 0.22, 0.26, 0.95, 0.57, 0.42,
0.38, 0.5, 0.31, 0.31, 0.12, 0.88, 0.55, 0.55, 0.31,
0.4, 0.5, 0.34, 0.53, 0.3, 0.41, 0.41, 0.46, 0.34,
0.22, 0.17, 0.28, 0.94, 0.62, 0.46, 0.41, 0.53, 0.34,
0.36, 0.1, 0.84),
n = c(240L, 240L, 240L, 240L, 240L, 240L, 240L, 240L, 240L, 240L,
240L, 240L, 240L, 240L, 240L, 240L, 240L, 240L, 240L, 240L,
240L, 240L, 240L, 240L, 258L, 258L, 258L, 258L, 258L, 258L,
258L, 258L, 258L, 258L, 258L, 258L, 258L, 258L, 258L, 258L,
258L, 258L, 258L, 258L, 258L, 258L, 258L, 258L)),
.Names = c("Year", "Response", "Proportion", "n"),
row.names = c(NA, -48L), class = c("tbl_df", "tbl", "data.frame"))
scale <- 10
# multiply latitudes by a factor of 10 to scale plot to good size in initial view
d$lat <- scale*d$Proportion - 90
d$long <- (as.numeric(d$Response)-1) * 360/24
p <- plot_ly(d[c(1:24,1,25:48,25),], lat=~lat, lon=~long, color = ~Year, colors=c('#F8756B','#00BDC2'),
type = 'scattergeo', mode = 'lines+markers', showlegend=T) %>%
layout(geo = list(scope='world', showland=F, showcoastlines=F, showframe=F,
projection = list(type = 'azimuthal equidistant', rotation=list(lat=-90), scale=5),
legend=list(x=0.7,y=0.85)))
p <- p %>% add_trace(type="scattergeo", mode = "text", lat=-79, lon=~long,
text=~Response, showlegend=F, textfont=list(size=10, color='#808080'))%>%
add_trace(type="scattergeo", mode = "text", showlegend=F, textfont=list(size=12),
lat=-90, lon=0,
text="")%>%
add_trace(type="scattergeo", mode = "text", showlegend=F, textfont=list(size=12,color='#808080'),
lat=-87.5, lon=0,
text="25%") %>%
add_trace(type="scattergeo", mode = "text", showlegend=F, textfont=list(size=12,color='#808080'),
lat=-85, lon=0,
text="50%") %>%
add_trace(type="scattergeo", mode = "text", showlegend=F, textfont=list(size=12,color='#808080'),
lat=-82.5, lon=0,
text="75%") %>%
add_trace(type="scattergeo", mode = "text", showlegend=F, textfont=list(size=12,color='#808080'),
lat=-80, lon=0,
text="100%")
l1 <- list(width = 0.5, color = '#808080', dash = "3px")
l2 <- list(width = 0.5, color = '#808080')
for (i in c(0.1, 0.25, 0.5, 0.75, 1))
p <- p %>% add_trace(lat=rep(-90, 100)-scale*i, lon=seq(0,360, length.out=100), type='scattergeo', mode='lines', line=l1, showlegend=F, inherit=FALSE)
for (i in 1:24)
p <- p %>% add_trace(lat=c(-90+scale*0.1,-90+scale), lon=rep(i*360/24,2), type='scattergeo', mode='lines', line=l2, showlegend=F, inherit=FALSE)
p
recharts is a R package to based on Echarts by Baidu, it is still in developing. Before running the example, you need to install recharts package.
devtools::install_github('yihui/recharts')
source("https://raw.githubusercontent.com/mwang27/recharts/master/R/echartR.R")
player <- data.frame(name=c(rep("Philipp Lahm",8),rep("Dani Alves",8)),
para=rep(c("Passing%","Key passing","Comp crosses",
"Crossing%","Successful dribbles",
"Dispossessed","Dribbled past","Fouls"),2),
value=c(89.67, 1.51, 0.97, 24.32, 0.83, 0.86, 1.15, 0.47,
86.62, 2.11, 0.99, 20.78, 1.58, 1.64, 0.9, 1.71))
echartR(player, x= ~para, y= ~value, series= ~name, type='radarfill',
symbolList='none', palette=c('firebrick1','dodgerblue'),
title='', subtitle= '(by @dataomics)')