2015-09-10 50 views
0

我正面臨着一些困難,以一些透明度來設置我的背景情節。簡單地說,只要我將alpha設置爲任何值,就會返回相同的不透明背景。 雖然有關於背景突出,如爲什麼設置背景的透明度(alpha)在ggplot中不起作用?

customize background to highlight ranges of data in ggplot

How to highlight time ranges on a plot?

ggplot2: highlight chart area

但不幸的是,是不是在這裏或那裏討論了這個問題的一些職位。 我將不勝感激您的意見

這裏是演示

install.packages("ggplot2") 

首先是一些數據,利用geom_rect

ggplot(mtcars, aes(x=wt, y=qsec)) + 
geom_point(color="black",size=8) + 
theme_bw() + 
geom_rect(aes(xmin=4,xmax=5,ymin=14,ymax=Inf),alpha=0.9,fill="green") 

阿爾法播放不會幫助,最終,這就是我得到

data from mtcars

使用annotate函數,我也無法生成它。

+2

您的'alpha'值太高。參見'alpha = 0.05'。 –

+2

包名是'ggplot2',而不是'ggplot'。附加dataftrames通常是一個壞主意。 –

+0

通常,您希望切換'geom_point'和'geom_rect'的順序。 – Axeman

回答

2

您的值爲alpha太高。

enter image description here