R中ggplot图的背景色的对角渐变 [英] Diagonal grading of background color of ggplot graph in R
本文介绍了R中ggplot图的背景色的对角渐变的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我希望在背景逐渐褪色的情况下以以下样式制作图形.更具体地说,我希望得到对角衰落
我已经这样绘制了图形:
ggplot(数据)+aes(x = Data $ log.avg,y = Data $ CoV)+geom_point(alpha = 0.3)+ggtitle(对udbetalingskonti的过大")+geom_text(aes(label = ifelse(Data $ log.avg> 1.6 | Data $ CoV> 2&数据$ log.avg>-0.5,as.character(Data $ KT),'')),hjust = -0.2,vjust = -0.2,size = 3)+labs(x ="Avg",y =变异系数")
解决方案
请考虑以下内容:
`aes(x,y,fill = x + y)`#右上角最暗aes(x,y,fill = y-x)#在左上角最暗
要与切换到 high
&的开关组合使用 scale_fill_gradient
low
自变量I am looking to do a graph in the following style, with a fading background. More specifically, I hope to get a diagonal fading
I have already made the graph as so:
ggplot(Data) +
aes(x=Data$log.avg, y=Data$CoV) +
geom_point(alpha = 0.3) +
ggtitle("Oversigt over udbetalingskonti") +
geom_text(aes(label=ifelse(Data$log.avg > 1.6 | Data$CoV > 2 &
Data$log.avg > -0.5 , as.character(Data$KT),'')),hjust=-0.2, vjust=-0.2, size=3) +
labs(x="Avg",y="Coefficient of Variation")
解决方案
This basic approach helped me with a similar problem.
## create a diag gradient background
## create a df to supply the background to geom_tile
df <- expand.grid(x=-100:100, y=-100:100) # dataframe for all combinations
## plot
ggplot(df, aes(x, y, fill=x+y)) + # map fill to the sum of x & y
geom_tile(alpha = 0.75) + # let the grid show through a bit
scale_fill_gradient(low='light blue', high='steelblue4') # choose your colors
Result:
Consider the following:
`aes(x, y, fill=x+y)` # darkest in the top right corner
`aes(x, y, fill=y-x)` # darkest in the top left corner
To be used in combo with switches to the high
& low
arguments in scale_fill_gradient
这篇关于R中ggplot图的背景色的对角渐变的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文