The Radar chart and its caveats - From data to Viz

文章推薦指數: 80 %
投票人數:10人

A radar or spider or web chart is a two-dimensional chart type designed to plot one or more series of values over multiple quantitative variables . TheRadarchartanditscaveats AcollectionofcommondatavizcaveatsbyData-to-Viz.com Code ShowAllCode HideAllCode Definition Aradarorspiderorwebchartisatwo-dimensionalcharttypedesignedtoplotoneormoreseriesofvaluesovermultiplequantitativevariables.Eachvariablehasitsownaxis,allaxesarejoinedinthecenterofthefigure. Let’sconsidertheexamresultsofastudent.Hehasamarkrangingfrom0to20fortentopicslikemath,sports,statistics,andsoon.Theradarchartprovidesoneaxisforeachtopic.Theshapeallowsyoutoseewhichtopicsthestudentperformedwellorpoorlyin. #Libraries library(tidyverse) library(viridis) library(patchwork) library(hrbrthemes) library(fmsb) library(colormap) #Createdata set.seed(1) data%slice(3)%>%t()%>%as.data.frame()%>%add_rownames()%>%arrange(V1)%>%mutate(rowname=factor(rowname,rowname))%>% ggplot(aes(x=rowname,y=V1))+ geom_segment(aes(x=rowname,xend=rowname,y=0,yend=V1),color="grey")+ geom_point(size=5,color="#69b3a2")+ coord_flip()+ theme_ipsum()+ theme( panel.grid.minor.y=element_blank(), panel.grid.major.y=element_blank(), axis.text=element_text(size=48), legend.position="none" )+ ylim(0,20)+ ylab("mark")+ xlab("") Supportingtheranking-Intheaboveexample,thelollipopplotisordered.Itallowsyoutoseeinstantlywhichtopichadthebestmarkandwhattherankingofeachtopicwas.Thisismoredifficultwithradarchartswheretherearenostartsandends. Categoryorderhasahugeimpact-Radarchartreaderswillprobablyfocusontheshapeobserved.Thiscanbemisleadingsincethisshapehighlydependsontheorderingofcategoriesaroundtheplot.Seethesechartsmadeusingthesamedata,butchangingthecategoryordering: #Createdata:noteinHighschoolforJonathan: set.seed(7) data%slice(3)%>%t()%>%as.data.frame()%>%add_rownames()%>%arrange(V1)%>%mutate(rowname=factor(rowname,rowname))%>% ggplot(aes(x=rowname,y=V1))+ geom_segment(aes(x=rowname,xend=rowname,y=0,yend=V1),color="grey")+ geom_point(size=5,color="#69b3a2")+ coord_flip()+ theme_ipsum()+ theme( panel.grid.minor.y=element_blank(), panel.grid.major.y=element_blank(), axis.text=element_text(size=48), legend.position="none" )+ ylim(0,20)+ ylab("mark")+ xlab("") Ifyouhavetwoseriestoplot,youcanstillplaywithbarplotandlollipopplots.Hereisanexamplewith2series.Itfocusesonthefirststudent(dark)andallowsyoutoseehowanotherstudent(light)performedincomparison. #Createdata:noteinHighschoolforJonathan: set.seed(1) data%slice(c(3,4))%>%t()%>%as.data.frame()%>%add_rownames()%>%arrange(V1)%>%mutate(rowname=factor(rowname,rowname))%>% ggplot(aes(x=rowname,y=V1))+ geom_segment(aes(x=rowname,xend=rowname,y=V2,yend=V1),color="grey")+ geom_point(size=5,color="#69b3a2")+ geom_point(aes(y=V2),size=5,color="#69b3a2",alpha=0.1)+ coord_flip()+ theme_ipsum()+ theme( panel.grid.minor.y=element_blank(), panel.grid.major.y=element_blank(), axis.text=element_text(size=48) )+ ylim(0,20)+ ylab("mark")+ xlab("") Ifyouhaveafewseriestoplot,usingfacetingwithbarplotorlollipopplotcanperhapsdothetrick: #Createdata:noteinHighschoolforJonathan: set.seed(1) data%slice(c(3:6))%>% t()%>% as.data.frame()%>% add_rownames()%>% arrange(V1)%>% mutate(rowname=factor(rowname,rowname))%>% gather(key=name,value=mark,-1) #Recode data$name%ggplot(aes(x=rowname,y=mark))+ geom_bar(stat="identity",fill="#69b3a2",width=0.6)+ coord_flip()+ theme_ipsum()+ theme( panel.grid.minor.y=element_blank(), panel.grid.major.y=element_blank(), axis.text=element_text(size=48) )+ ylim(0,20)+ ylab("mark")+ xlab("")+ facet_wrap(~name,ncol=4) Ifyouhavealotofseriestoplot,orifyourvariablesdonothavethesamescale,thenthebestoptionisprobablytoswitchtoaparallelcoordinatesplot. library(GGally) data% ggparcoord( columns=1:4,groupColumn=5,order="anyClass", showPoints=TRUE, title="ParallelCoordinatePlotfortheIrisData", alphaLines=0.3 )+ scale_color_viridis(discrete=TRUE)+ theme_ipsum() Comments Anythoughtsonthis?Foundanymistake?Disagree?Pleasedropmeawordontwitterorinthecommentsectionbelow:   AworkbyYanHoltzfordata-to-viz.com  



請為這篇文章評分?