Dan*_*tes 2 r border axes ggplot2
R中是否有方法在x或y轴标签周围绘制框/边框,可能是有角度的标签?
我一直在使用ggplot创建瓷砖图表并找到在数据本身中放置标签的代码(通过geom_label:设置ggplot2标签背景颜色, 但不在轴本身的标签周围.
图表示例:
library(grid)
element_custom <- function() {
structure(list(), class = c("element_custom", "element_text"))
}
element_grob.element_custom <- function(element, label="", ...) {
tg <- textGrob(label)
padding <- unit(1,"line")
rg <- rectGrob(width=grobWidth(tg)+padding, height=grobHeight(tg)+padding)
gTree(children=gList(rg, tg), height=grobHeight(tg) + padding, cl="custom_axis")
}
heightDetails.custom_axis <- function(x) x$height + unit(2,"mm") # fudge
ggplot(iris, aes(Sepal.Length, Sepal.Width)) +
geom_line() +
labs(x= "Axis title")+
(theme_grey() %+replace% theme(axis.title.x = element_custom()))
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
482 次 |
| 最近记录: |