ggplot2: different alpha values for border and filling of geom_point ggplot2: different alpha values for border and filling of geom_point r r

ggplot2: different alpha values for border and filling of geom_point


A simpler way, available here because you want the same alpha and color for all, is to specify the fill in the geom_point command using alpha. Alternatively one could also "old-fashioned" method of specifying transparency with two additional hex codes, like this, #00000044.

ggplot(data=comp24, aes(x=spatial, y=lnfit, shape=spatial)) +   geom_point(position=position_jitter(width=0.5), size=1.75,               fill=alpha("black", 0.2), stroke=0.3)


This should works for you :

ggplot(data=comp24, aes(x=spatial, y=lnfit, colour=spatial, fill=spatial, shape=spatial, backgroundColor="white", na.rm=T))+geom_point(position=position_jitter(w=0.5), size=1.75, stroke=0.3)+scale_colour_manual(name="spatial structure", values = c("black", "black", "black"))+scale_fill_manual(name="spatial structure", values =alpha(c("black","black", "black"),0.2))

Let me know


To achieve the desired plot I will use position_nudge function.

First I create a nudge vector with a uniform probability distribution of the same length as the data points. This can be done as below

set.seed(10)nudgeWidth = 0.5nudgeVec <- (runif(nrow(comp24))-0.5)*nudgeWidth

Now I use the above nudge vector "nudgeVec" to get the desired plot

plot1 <- ggplot(data=comp24, aes(x=spatial, y=lnfit, backgroundColor="white", na.rm=T))plot1 <- plot1 + geom_point(position=position_nudge(x = nudgeVec),size=10.75,aes(alpha=0.2, stroke=0.5,shape=(as.integer(comp24$spatial)+14)))plot1 <- plot1 + scale_colour_identity()plot1 <- plot1 + scale_shape_identity()plot1 <- plot1 + geom_point(position = position_nudge(x = nudgeVec),size=10.75,aes(alpha=1, stroke=0.5, colour="black",shape=(as.integer(spatial)-1)))plot1

The output looks like thisDesired Plot