Reputation: 11
I am having trouble reversing the axis in this example. I would like to start at 8 in he middle of the chart and then 1 at the top. At the moment the middle is 0 and end is 8.
library(fmsb)
Create data: note in High school for Jonathan:
data=as.data.frame(matrix( sample( 1:8 , 10 , replace=T) , ncol=10))
colnames(data)=c("math" , "english" , "biology" , "music" , "R-coding", "data-viz" , "french" , "physic", "statistic", "sport" )
To use the fmsb package, I have to add 2 lines to the dataframe: the max and min of each topic to show on the plot!
data=rbind(rep(8,1) , rep(1,1) , data)
The default radar chart proposed by the library:
radarchart(data)
Custom the radarChart !
radarchart( data , axistype=1 ,
#custom polygon
pcol=rgb(0.2,0.5,0.5,0.9) , pfcol=rgb(0.2,0.5,0.5,0.5) , plwd=4 ,
#custom the grid
cglcol="grey", cglty=1, axislabcol="grey", caxislabels=seq(0,8,2), cglwd=0.8,
#custom labels
vlcex=0.8
)
Upvotes: 1
Views: 871
Reputation: 37661
You seem to want to have a marking only for even numbered values, but then you won't get 1 as an axis marker. I will make it go from 8 to 0, instead of from 8 to 1. All that you need to do is reverse the axis limits that you specified and also reverse the axis labels.
data=as.data.frame(matrix( sample( 1:8 , 10 , replace=T) , ncol=10))
colnames(data)=c("math" , "english" , "biology" , "music" ,
"R-coding", "data-viz" , "french" , "physic", "statistic", "sport" )
## Changes lower limit to 0
data=rbind(rep(8,1) , rep(0,1) , data)
radarchart(data)
## Reverse max and min (how points will be plotted)
data2 = data
data2[1:2,] = data2[2:1,]
radarchart( data2, axistype=1 ,
#custom polygon
pcol=rgb(0.2,0.5,0.5,0.9) , pfcol=rgb(0.2,0.5,0.5,0.5) , plwd=4 ,
#custom the grid
cglcol="grey", cglty=1, axislabcol="grey",
# Reverse axis labeling
caxislabels=seq(8,0,-2), cglwd=0.8,
#custom labels
vlcex=0.8
)
Upvotes: 1