没有坐标轴或网格的ggplot2主题 [英] ggplot2 theme with no axes or grid
本文介绍了没有坐标轴或网格的ggplot2主题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图在没有超出数据范围的情况下制作一个情节。没有轴;没有网格;无题;只是情节。
但我一直得到额外的利润和填充,我无法删除。
<$ p $ ($)b
$ b $ axis.text.x = element_blank(),
axis.text.y = element_blank(),
axis.ticks = element_blank(),
axis.title.x = element_blank(),
axis.title.y = element_blank(),
#axis.ticks.length = unit(0,lines),#Error
axis.ticks.margin = unit(c( 0,0,0,0),lines),
legend.position =none,
panel.background = element_rect(fill =gray),
panel.border = element_blank(),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
panel.margin = unit(c(0,0,0) ,0),lines),
plot.background = element_rect(fill =blue),
plot.margin =单位(c(0,0,0,0),lines )
)
ggplot()+
geom_area(data = economics,aes(x = date,y = unemploy ),linetype = 0)+
theme_bare
产生此图片:
我想要的是:
我无法弄清楚如何摆脱蓝色和使深灰色与边缘齐平。
任何人都可以提供一些建议吗?
p < - ggplot()+ geom_area(data = economics,aes(x =日期,y =失业),linetype = 0)+
scale_x_date(expand = c(0,0))+ scale_y_continuous(expand = c(0,0))+
theme(line = element_blank ),
text = element_blank(),
title = element_blank())
$ b $ gt gt < - ggplot_gtable(ggplot_build(p))
ge < - subset (gt $ layout,name ==panel)
grid.draw(gt [ge $ t:ge $ b,ge $ l:ge $ r])
I am trying to make a plot with no information beyond the data. No axes; no grid; no title; just the plot.
But I keep getting extra margins and padding that I can't remove.
library(ggplot2)
library(grid)
theme_bare <- theme(
axis.line = element_blank(),
axis.text.x = element_blank(),
axis.text.y = element_blank(),
axis.ticks = element_blank(),
axis.title.x = element_blank(),
axis.title.y = element_blank(),
#axis.ticks.length = unit(0, "lines"), # Error
axis.ticks.margin = unit(c(0,0,0,0), "lines"),
legend.position = "none",
panel.background = element_rect(fill = "gray"),
panel.border = element_blank(),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
panel.margin = unit(c(0,0,0,0), "lines"),
plot.background = element_rect(fill = "blue"),
plot.margin = unit(c(0,0,0,0), "lines")
)
ggplot() +
geom_area (data=economics, aes(x = date, y = unemploy), linetype=0) +
theme_bare
Produces this image:
What I want is this:
I can't figure out how to get rid of the blue and make the dark gray flush with the edges.
Could any one offer some advice?
解决方案
Here is the way to plot only the panel region:
p <- ggplot() + geom_area (data=economics, aes(x = date, y = unemploy), linetype=0) +
scale_x_date(expand = c(0,0)) + scale_y_continuous(expand = c(0,0)) +
theme(line = element_blank(),
text = element_blank(),
title = element_blank())
gt <- ggplot_gtable(ggplot_build(p))
ge <- subset(gt$layout, name == "panel")
grid.draw(gt[ge$t:ge$b, ge$l:ge$r])
这篇关于没有坐标轴或网格的ggplot2主题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文