我有一个如下表:
A1 A2 A3
Tree Precision 0.4042553 0.9586207 0.9251701
Recall 1 1 1
F1 0.5757576 0.9788732 0.9611307
Radial Precision 0.9166667 0.9030303 0.9006211
Recall 0.2820513 1 1
F1 0.4313725 0.9490446 0.9477124
Polynomial Precision 0.7857143 0.9125 0.8875
Recall 0.2820513 0.9798658 0.9793103
F1 0.4150943 0.9449838 0.9311475
我想绘制此表,例如“精度”,“调用”和“ F1”值在y轴上,而“ A1至A3”在x轴上。我也想在地块上指定不同的模型。关于如何执行此操作的任何想法?
答案 0 :(得分:1)
一种使用上述轴显示df
的方法,可以使用以下分组条形图
# This is for setting up your dataframe, you already have this
A1 = c(0.4042553,0.9586207,0.9251701,1,1,1,0.5757576,0.9788732,0.9611307)
A2 = c(0.9166667,0.9030303,0.9006211,0.2820513,1,1,0.4313725,0.9490446,0.9477124)
A3 = c(0.7857143,0.9125,0.8875,0.2820513,0.9798658,0.9793103,0.4150943,0.9449838,0.9311475)
df =data.frame(A1,A2,A3)
colnames(df) = c("A1","A2","A3")
# The rownames are important for the following melt function below.
# The "_T", "_R" and "_P" in some names were inserted for variable differentiation.
rownames(df) = c("Tree Precision","Recall_T","F1_T","Radial Precision","Recall_R","F1_R","Polynomial Precision","Recall_P","F1_P")
df
准备好后,重塑开始:
df$vartag <- row.names(df) # Insertion of your rownames as extra column (vartag = variable_tag; but you can name it whatever you want
library(reshape2) # For the melt function
library(ggplot2) # For plotting
df.long <- melt(df, "vartag")
ggplot(df.long, aes(x=variable, y=value, fill=variable)) +
geom_bar(stat="identity", position="dodge") +
facet_wrap(~vartag, ncol=3)
因此,您应该获得一个3x3的绘图,每个绘图中有三个条(请参见下文)。
如果您希望以其他方式显示值,则应该访问this site来查找所需图形的名称,并应编辑问题。