在fivethyeye.com的图表中,它们主要在轴的顶部刻度线上包含y轴标签。一个例子在本卡斯尔曼的图形被认为是从他2016年2月12日的文章“沙特是赢得它的战争对美国石油工业”:The number for the top of the y-axis scale includes the unit, like $150/barrel or 1,500 rigs.如何在R中使用ggplot2在轴刻度标记上添加轴标签,类似于fivethirtyeight样式?
我已经修改从ggthemes包一个主题GGPLOT2:
library(ggplot2)
library(ggthemes)
theme_fivethirtyeight_mod <- function (base_size = 12, base_family = "sans") {
(theme_foundation(base_size = base_size, base_family = base_family) +
theme(line = element_line(colour = "black"), rect = element_rect(fill = ggthemes_data$fivethirtyeight["ltgray"], linetype = 0, colour = NA), text = element_text(colour = ggthemes_data$fivethirtyeight["dkgray"]),
axis.text = element_text(color = 'black'), axis.ticks = element_blank(), axis.line = element_blank(),
legend.title = element_blank(), legend.background = element_rect(fill="gray90", size=.5, linetype="dotted"),
legend.position = "bottom", legend.direction = "horizontal", legend.box = "vertical",
panel.grid = element_line(colour = NULL), panel.grid.major = element_line(colour = ggthemes_data$fivethirtyeight["medgray"]),
panel.grid.minor = element_blank(), plot.title = element_text(hjust = 0, size = rel(1.5), face = "bold"),
plot.margin = unit(c(1, 1, 1, 1), "lines"), strip.background = element_rect()))
}
我想“后IP”添加到这个曲线图的y轴和顶部的“IP之前”与x轴的最右边的刻度(其使用该主题): A scatterplot showing Innings Pitched before an injury versus after an injury for 81 baseball pitchers.
在此先感谢您的帮助!
的[ggthemes包(https://cran.r-project.org/web/packages/ ggthemes/vignettes/ggthemes.html)提供了五十八岁的主题。 – Thomas
但是,ggthemes软件包不允许使用第五个样式的轴标签。另外,fivethirthyeight主题将'axis.text'设置为'element_blank()',我需要某种形式的标签。 @Thomas –