在ggplot中,当关闭裁剪时,alpha
这是一个例子:
## create a dummy data frame:
library(tidyverse)
num_lines <- 10
start_values = runif(num_lines,min = 0,max = 5)
end_values = start_values + runif(num_lines,max = 7)
df <- data.frame(from = start_values,to = end_values,value = runif(num_lines,max = 100),name = letters[seq(1,num_lines)])
plot_df <- df %>% gather(milestone,date,-name,- value)
## draw it:
ggplot(plot_df,aes(x = date,y = name)) +
geom_line(aes(size = value),color = "grey50",alpha = 0.9) + #### lines are not drawn
geom_line(linetype = "dashed",alpha = 1.0) + #### lines are drawn
annotate("label",x = num_lines/2,y = num_lines + 1,label = "A label") + #### a label that should not be clipped...
coord_cartesian(clip = "off") + #### ...therefore: clip = "off"
ggtitle("Example")
在运行代码时,未绘制第一个(... alpha = 0.9)的geom_line
,而第二个的行为符合预期。删除coord_cartesian(clip = "off")
时,两个geom_lines
都会出现。
这是ggplot中的错误还是我做错了什么?