[英]ggplot axis: different y-axis on left and right of plot
I have the following data; 我有以下数据;
https://www.dropbox.com/s/at2f2zni7s1hnzm/results.csv?dl=0 https://www.dropbox.com/s/at2f2zni7s1hnzm/results.csv?dl=0
When I plot all three plots using the following; 当我使用以下方法绘制所有三个图时;
library(ggplot2)
library(pROC)
roc <- roc(results$testactual, results$pred)
ggroc(roc) +
geom_density(data = results %>%
filter(testactual == 0), aes(pred), color='green') +
geom_density(data = results %>%
filter(testactual == 1), aes(pred), color='black')
I am able to obtain 3 plots on the same graph but the axis are not as I would have hoped. 我可以在同一张图上获得3个图,但是轴不如我所希望的那样。
I am trying to make it such that the y-axis for the density plots are displayed onto the right side and the roc
plots y-axis are on the left. 我正在尝试使密度图的y轴显示在右侧,而
roc
图的y轴在左侧。
Finally sort the x-axis so that the 1 is on the right side and the zero is on the left side (however I think I can manage this as I have run into this problem before) 最后,对x轴进行排序,以使1在右侧,零在左侧(但是我认为我可以解决这个问题,因为之前遇到过这个问题)
Direct R link to data: 直接R链接到数据:
results <- read.csv(url("https://www.dropbox.com/s/at2f2zni7s1hnzm/results.csv?dl=1"))
EDIT: Just plotting the density plots: 编辑:只是绘制密度图:
Plot of the ROC plot ROC图的图
Use the sec.axis parameter. 使用sec.axis参数。 Also you can use
..scaled..
to scale your densities to max of 1. 您也可以使用
..scaled..
将密度调整为最大1。
roc <- roc(results$testactual, results$pred)
ggroc(roc) +
geom_density(data = results %>%
filter(testactual == 0), aes(x=pred, y=..scaled..), color='green') +
geom_density(data = results %>%
filter(testactual == 1), aes(x=pred, y=..scaled..), color='black') +
scale_y_continuous(name = "Density", sec.axis = sec_axis(~., name = "Sensitivity"))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.