noHup - roc
type: channel
link: http://www.nohup.cc/tag/roc/
items: 使用R语言ggplot2包画图时的一个不兼容问题

使用R语言ggplot2包画图时的一个不兼容问题
type: item
date: 2016-01-24T11:33:00+00:00
description: Overview1. 问题描述2. 错误复现2.1 ggthemes2.2 安装devtools包2.3 从github上更新ggthemes3. 解决方法 Overview 昨天写了个R语言脚本，主要是借助ROCR包画ROC曲线，只是最后画图时，没用ROCR提供的plot函数画ROC曲线，而是用ROCR处理了数据后，提取了画图的数据，用ggplot2包画了ROC曲线。因为ggplot2可以提供强大的自定义绘图功能，没想到也正是这个自定义样式函数，在移植的时候出现了一些兼容性问题。 1. 问题描述 我使用的ggplot2样式函数，是一个我已经用了一年多的样式，专门写在了一个名字叫style.R的R文件中，内容如下： library(grid) theme_custom <- function (base_size = 10, base_family = "serif") { theme_grey(base_size = base_size, base_family = base_family) %+replace% theme( line = element_line(colour = "black", size = 1, linetype = 1, lineend = "butt"), rect = element_rect(fill = "white", colour = "black", size = 1, linetype = 1), text = element_text(family = base_family, face = "plain", colour = "black", size = base_size, hjust = 0.5, vjust = 0.5, angle = 0, lineheight = 0.9), axis.text = element_text(size = rel(0.8), colour = "grey50"), strip.text = element_text(size = rel(0.8)), ## used to delete the text up the picture #strip.text = element_blank(), axis.line = element_blank(), axis.text.x = element_text(family = base_family, size = base_size * 1.2, lineheight = 0.8, vjust = 1.2), axis.text.y = element_text(family = base_family, size = base_size * 1.2, lineheight = 0.8, hjust = 1.2), axis.ticks = element_line(colour = "black", size=0.2), axis.title.x = element_text(family = base_family, size = base_size*1.5, vjust = 0.5), axis.title.y = element_text(family = base_family, size = base_size*1.5, angle = 90, vjust = 0.5), axis.ticks.length = unit(0.15, "cm"), axis.ticks.margin = unit(0.1, "cm"), legend.background = element_rect (fill="white",colour="grey50", size=0.1, linetype=1), legend.margin = unit(0.5, "cm"), legend.key = element_rect(fill = "grey95", colour = "white"), legend.key.size = unit(1.2, "lines"), legend.key.height = NULL, legend.key.width = NULL, legend.text = element_text(family = base_family, size = base_size * 1.2), legend.text.align = NULL, ##legend.title = element_text(family = base_family, size = base_size * 3, face = "bold", hjust = 1), legend.title =…