我正在尝试在每个数据集大小中使用3种不同工具制作箱形图,如下所示:
ggplot(data1, aes(x = dataset, y = time, color = tool)) + geom_boxplot() +
labs(x = 'Datasets', y = 'Seconds', title = 'Time') +
scale_y_log10() + theme_bw()
但是我需要将x轴转换为对数比例。为此,我需要对每个数据集进行数字化处理,以将其转换为对数比例。即使不对其进行转换,它们的外观也如下所示:
ggplot(data2, aes(x = dataset, y = time, color = tool)) + geom_boxplot() +
labs(x = 'Datasets', y = 'Seconds', title = 'Time') +
scale_y_log10() + theme_bw()
我检查了箱线图参数和es的分组参数,但无法解决我的问题。起初,我认为此问题是由扩展到日志引起的,但是删除这些元素并不能解决问题。
我到底想念什么?谢谢...
文件位于此链接中。“ data2”是“ data1”的数字化版本。
您的问题是一个艰难的cookie,但我从中学到了一些新东西!
仅使用group = dataset
还不够,因为您还需要注意tool
变量。深入研究后,我发现了使用该功能的帖子interaction()
。
这是所缺少的把戏。您group
之所以要使用,是因为您没有在x
值中使用因数,而是需要tool
在数据分离中包含(因此使用interaction()
它将计算两个变量之间的可能交叉)。
# This is for pretty-printing the axis labels
my_labs <- function(x){
paste0(x/1000, "k")
}
levs <- unique(data2$dataset)
ggplot(data2, aes(x = dataset, y = time, color = tool,
group = interaction(dataset, tool))) +
geom_boxplot() + labs(x = 'Datasets', y = 'Seconds', title = 'Time') +
scale_x_log10(breaks = levs, labels = my_labs) + # define a log scale with your axis ticks
scale_y_log10() + theme_bw()
这个情节
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句