在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 –