Shading a kernel density estimate between two points - with transparency - r

So I like this answer: Shading a kernel density plot between two points.
But I want to extend the question.
Here is what I have right now, and I am not satisfied.
I want to make the rectangles partially see-through (transparent, alpha).
How do I do that?
For those who are curious the x-label is an AIC difference.

Related

Hey how can I adjust the thickness of the survival curve in ggsurvplot?

The simple size parameter does not work. Do you have any other options? I would like to make the curve smaller.

Confidence interval square in a plot with one variable in each axis in ggplot

Although it might sound easy at first, I do not have a scatterplot. And I think that is what make this question challenging. I am having this plot, which comes from this question.
Summing up, each axis represents a variable that is not connected to the other. It is not an XY scatterplot, as you see.
I wonder to know if there is any possibility to trace the 95% confidence interval for the mean in both variables, and draw a square in the middle of the plot representing the overlapping area among both datasets.
The result might be something similar to this, bearing in mind that 95CL represented do not correspond to reality (just for the sake of illustrating how it might appear):
Here is a another question which deals with this situation, but not using ggplot.

R - Make lines() points/line thickness reflect density of points?

I know how to change the thickness of points/lines manually; however I wish to plot 1000+ series on the same graph so that the resulting graph has darker or lighter points depending on the density of points at that location. ie, the more points centered there the darker the area gets.
What I have now is just this:
plot(df[,1],ylim=c(0,1))
for(i in 2:ncol(df)){
lines(df[,i],col='grey',type='p')
}
Which gives me the following graph. Unfortunately there's so many points that it just gives me a uniform grey line, instead of telling me how these points are distributed.

space points in a scatter plot in R

I am plotting a scatter plot in R, however I have many data points and they overlap. I want to have a plot where there no overlaps and maintain a reasonable size of the data . This is the image of the scatter. On the top side is where the data are clustered.
This is the code plot(data2,col="red",pch=21,cex=0.7)
Could you put a reproducible code to check.
One thing you can do is may be increase the space between y axis interval.

ggplot - specify coordinate in middle of plot, regardless of scale

I would like to add a rectangle to my scatter plot to specify a region. I know I can do this by calling geom_polygon and specifying the X- and Y-coordinates of the corners. However, I would like to make sure the rectangle is always half (or another fraction) of the height of the plot, regardless of what the scale of the points on the plot is.
Is there any way I can specify the coordinates of the corners with something like "fraction of plotting region" as the unit?
The only other option I see is to try to predict the scale of the plot by looking at the min() and max() of the points that I am plotting and then calculating the coordinates for the box based on that, but that becomes a lot more complicated once you start faceting and so on...

Resources