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

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.

Related

Remove 2D line distortion

I want to draw a straight line using X and Y pixels but my input data is not streamlined. So I tried to draw the line.And it looks like this How should I remove distortion using interpolation or any other techniques.
Actually my problem is This is my expected graph. But I am getting this distorted image with simulation Distorted lines and curves because of uneven pixels. I want to streamline this graph

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.

Shading a kernel density estimate between two points - with transparency

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.

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...

stop ggplot2 from dropping data points outside of axis limits?

If I make a line plot (a time series, for example) and set my axis limits, I want the line to continue off the plot when points are outside of the axis limits, and then come back into the plot for the next point that is within the axis limits. Right now, it seems that ggplot2 will just drop the points completely and give me a an "Error:" message.
If you limit your axes by reducing the axis scale (scale_x_continuous(limits=...)), then that is the expected behavior. By adjusting the scale, you are defining what data should be part of the plot. If you want to use all the data, but just zoom in on a particular region of the axes, you want to use coord_cartesian(xlim=..., ylim=...) instead.

Resources