r - 将 ggplot 标题定位在图的右上角

标签 r ggplot2

我正在使用优秀的 theme_minimal()在白色背景的 ggplot0.9.3 中找到。我想将我的情节的标题放在情节右上角的自定义位置。在下面的例子中,我知道 xy值,但我想知道是否有办法通过 xmaxymax值以确保文本放置在右上角。理想情况下,文本应正确对齐。

#example plot
p <- qplot(mpg, wt, data = mtcars, colour = cyl)
p +  annotate("text", x = 30, y = 5, label = "Custom Title")

#what I would like
p + annotate("text", y= ymax, x =xmax_or_RightJustified)

最佳答案

你可以做

p + annotate("text",  x=Inf, y = Inf, label = "Some text", vjust=1, hjust=1)

关于r - 将 ggplot 标题定位在图的右上角,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14928711/

相关文章:

roxygen2 未完全更新描述文件

r - 如何使用 pROC 的 ggroc 将 AUC 添加到多 ROC 图中

r - axis.break和ggplot2或gap.plot?情节可能太复杂了

r - ggplotly:悬停时重命名工具提示

r - 如何构建排序条形图

r - RStudio 中的半透明

r - 将带时间戳的数据与另一个数据集中最接近的时间进行匹配。正确矢量化?更快的方法?

rbind 具有不同列的数据框列表

r - 使用 ggplot2 沿平滑曲线绘制直方图或密度

r - (Rcpp, Armadillo ) 将 arma::vec 转换为 arma::mat