使用的程式碼如下:
speeds <- list("Default" = c(203,182,172,181,185,202,190,186,171,174,185,208,183,194,163),
"Default\n40c"=c(246,245,242,245),
"IntelMPI" = c(195,107,196,207,199,198,208,199,202),
"Cuda8" = c(196,184,167,167,204),
"AVX512" = c(151,154,177,177,183),
"E7-8850\n40c" = c(117,115,116,120),
"E5-2640v4\n1gx" = c(223,225,223,218))
library(plyr)
performance <- ldply(speeds, data.frame) # convert list to data.frame
names(performance) <- c("Type", "Speed") # Rename the column of the data frame "performance"
library(ggplot2)
p <- ggplot(performance, aes(x=Type, y=Speed, fill=Type)) + # Source data is "performance", fill the box
labs(title="GROMACS on Taiwania",x="Configuration", y = "Performance (ns/day)") +
theme(legend.position="none", # Don't show legend
plot.title=element_text(size=rel(2.0), face="bold"), # Font of plot title
axis.title=element_text(size=rel(1.5), face="bold"), # Font of axis title
axis.text.x=element_text(size=rel(1.5), angle=0), # Font of x-axis label
axis.text.y=element_text(size=rel(1.5), angle=15), # Font of y-axis label
axis.line=element_line(size = 3, colour = "grey80")) + # Axis with gray
geom_boxplot(outlier.colour="black", outlier.shape=16, outlier.size=2) + # Boxplot, dealting with outlier color, shape and size
coord_cartesian(ylim = c(0, 250)) + # the range of y-axis
geom_jitter(shape=20, size=3, position=position_jitter(0.2)) + # data points show in black dot
stat_summary(fun.y=mean, geom="point", shape=8, size=3, color="red") + # mean points shown in red asterisk
scale_x_discrete(limits=c("Default","Default\n40c","IntelMPI","Cuda8","AVX512","E7-8850\n40c","E5-2640v4\n1gx")) +
scale_fill_brewer(palette="Greens") # the above change the order of x-axis, and using gradient green
p # Plot the Boxplot!!
參考資料
- ggplot2 box plot : Quick start guide - R software and data visualization
上面的程式碼主要是參考這篇文章寫出來的
裡面有說明怎樣加入平均值的點到boxplot之中 - R ggplot2 Jitter:在boxplot裡面加入資料點的數據
這篇除了boxplot,還有介紹更進階的violin plot,可以看到分佈 - R的ggplot2基本概念
- R語言中的資料結構, How to use lists in R:使用list存取資料
- Convert list to data frame, mropa的回應:將list轉換成data frame
- ggplot2 function reference from tidyverse
- R ggplot boxplot: change y-axis limit:更改y軸的範圍
- ggplot2 colors : How to change colors automatically and manually?:調整顏色
- Changing font size and direction of axes text in ggplot2:改變xy軸的說明文字
沒有留言:
張貼留言