ggplot:coord_笛卡尔坐标(clip=";off";)和alpha<;1.0隐藏几何图形线
在ggplot中,关闭剪裁时,alpha<1.0的线将被完全删除 下面是一个例子:ggplot:coord_笛卡尔坐标(clip=";off";)和alpha<;1.0隐藏几何图形线,r,ggplot2,R,Ggplot2,在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, min = 0, max = 7)
df <- data.frame(from = start_values, to = end_values,
value = runif(num_lines, min = 0, 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")
##创建虚拟数据帧:
图书馆(tidyverse)
num_line您的代码适合我(在虚线下,我看到不同厚度的灰色线条)。我使用的是ggplot 3.2.0。非常感谢-我使用的是R3.6.1(在普通的RGUI中)-那么R3.6.1可能有问题。如果您使用的是普通的RGUI,那么您将在什么图形设备上绘制绘图?有些人可能不支持透明度。我正在使用RStudio(免费下载),它有一个集成的绘图区域。很好的提示-我尝试了ggsave(“test.png”,device=“png”)
并且显示了粗线-因此这似乎是R GUI图形设备的问题。我投票关闭这个问题,因为这个问题是由于用于输出绘图的图形设备造成的。不是代码问题。