今天遇到一个有意思的问题,有人问我,如何生成一个黑白反转的图。
在R中,默认的图都是墨白的。咋弄呢?
其实很简单,把默认值改了就行了。
plot(1:5, 1:5)
op <- par(bg="black", col="white", col.axis="white",
col.main="white", col.sub="white", col.sub="white")
plot(1:5, 1:5)
par(op)
那么,在ggplot2中如何实现呢?
library(ggplot2)
theme_black <- function (base_size = 12, base_family = "")
{
theme(line = element_line(colour = "white", size = 0.5,
linetype = 1, lineend = "butt"),
rect = element_rect(fill = "black", colour = "black",
size = 0.5, linetype = 1),
text = element_text(family = base_family,
face = "plain", colour = "white",
size = base_size, hjust = 0.5,
vjust = 0.5, angle = 0,
lineheight = 0.9),
panel.grid = element_blank(),
panel.background = element_rect(fill="black"),
panel.border = element_rect(color="white", fill=NA),
axis.line = element_line(color = "white"),
axis.text.x=element_text(color="white"),
axis.text.y=element_text(color="white"),
axis.ticks=element_line(color="white")
)
}
ggplot(aes(x=cyl, y=mpg), data=mtcars) + geom_point(color="white")+ theme_black()
why do this ? just for fun ?
有人喜欢黑色背景的PPT。
我想问一个我最近遇到的问题,不显著的点是灰色的,显著的点是红色的,但是灰色的点太多导致红色的点都显示一半,就是说红色的点被灰色的点遮住了,这种情况下该怎么办。谢谢博主。
先画灰色的点。然后再画红色的点,红色的点通过cex放大一点。