[R-scripts] ggplot2 Kiviat Plot Using coord_polar Function

I ran out of time a couple of months ago and decided to use the following quick hack to generatea Kiviat plot using ggplot2’s coord_polar function.

The result

ggplot2 Kiviat plot

ggplot2 Kiviat plot

Sample Dataset Used

> dataset <- read.table('experiments-performance-kiviat.dat', header=TRUE, sep=',')
> dataset
Workload Indexing Ingestion OAI.PMH.data.provider     RSS.Feed       Search
1       100     0.86 0.1213379                   480 3.130493e+00 2.466736e+01
2       200     0.86 0.1166992                   980 5.613892e+00 4.787427e+01
3       400     1.14 0.1174316                  2000 1.099023e+01 9.738324e+01
4       800     1.32 0.1179199                  4120 2.089575e+01 1.919023e+02
5      1600     2.14 0.1170247                  5410 4.034625e+01 3.869901e+02
6      3200     3.13 0.1193034                  5940 7.885956e+01 7.683469e+02
7      6400     5.33 0.1194661                  6730 1.565882e+02 1.531056e+03
8     12800    10.61 0.1269531                  8370 3.099473e+02 3.093123e+03
9     25600    17.99 0.1186523                 11680 6.167455e+02 6.172219e+03
10    51200    35.66 0.1223145                 18900 1.237004e+03 1.248706e+04
11   102400    70.36 0.1350098                 33460 2.505255e+03 2.510874e+04
12   204800   148.22 0.1280111                 66950 5.117130e+03 4.930145e+04
13   409600  3618.62 0.1213379                139720 1.053439e+04 1.002673e+05
14   819200  8337.75 0.1241048                586450 1.374618e+05 7.365254e+06
15  1638400 19968.95 0.1243490               1937090 1.503809e+06 1.866471e+07
>

The plot

# import libraries
 require(ggplot2)
 require(reshape2)
 require(grid)
 require(scales)
 require(fmsb)
 require(ggthemes)

# import datafeeds
 dataset <- read.table("plot.experiments-performance-kiviat.dat", header=TRUE, sep=",")

# re-order and rename workloads
 dataset$Workload <- factor(dataset$Workload, levels=c(100, 200, 400, 800, 1600, 3200, 6400, 12800, 25600, 51200, 102400, 204800, 409600, 819200, 1638400), labels=c("100","200","400","800","1.6k","3.2k","6.4k","12.8k","25.6k","51.2k","102.4k","204.8k","409.6k","819.2k","1638.4k"))

# convert dataset to molten form for ggplot2
 experimentdataset <- melt(dataset, id.vars=c(1))

# rename/normalise performance evaluation aspects
 levels(experimentdataset$variable)[levels(experimentdataset$variable)=="Indexing"] <- paste("Index","")
 levels(experimentdataset$variable)[levels(experimentdataset$variable)=="Ingestion"] <- paste("Ingest","")
 levels(experimentdataset$variable)[levels(experimentdataset$variable)=="OAI.PMH.data.provider"] <- paste("OAI-PMH","")
 levels(experimentdataset$variable)[levels(experimentdataset$variable)=="RSS.Feed"] <- paste("Feed","")
 levels(experimentdataset$variable)[levels(experimentdataset$variable)=="Search"] <- paste("Search","")

# generate plot
ggplot(experimentdataset,
       aes(x=variable,
           y=value,
           colour=as.factor(Workload),
           group=as.factor(Workload))) +
  geom_line(aes(linetype=as.factor(Workload)),size=1.5) +
  coord_polar(theta="x", direction=-1) +
  scale_linetype_manual(values=c("solid","dashed","dotted","dotdash","longdash","solid","dashed","dotted","dotdash","longdash","solid","dashed","dotted","dotdash","longdash")) +
  scale_y_log10(breaks=trans_breaks("log10", function(x) 10^x), labels=trans_format("log10", math_format(10^.x))) +
  labs(x="", y="log10(Time [ms])") +
  theme_igray() +
  scale_colour_stata() +
  theme(legend.title=element_blank(),
        legend.position="bottom",
        legend.text=element_text(size=8),
        #legend.key.height=unit(0.35,"cm"),
        #plot.margin=unit(c(0.2,0.15,0.05,0.8),"cm"),
        plot.margin=unit(c(0.5,0.5,0,0.8),"cm"),
        strip.text = element_text(size=9),
        axis.text = element_text(size=8),
        axis.title.y = element_text(vjust=-0.2,size=10)) +
  guides(linetype = guide_legend(nrow = 3))
 @
 
Categories: Technical
Tags: , ,