I have two chromatograms I want plotted on the same axes.
I would like the plots to be transparent, so the first chart is not obscured. I have tried adjustcolor(..., alpha.f=0.3), the problem is that my chromatogram is so dense with datapoints that they overlap and the entire graph just ends up a solid color. The second histogram still obscures the first. Consider this example: col1 <- adjustcolor("red", alpha.f=0.3) col2 <- adjustcolor("blue", alpha.f=0.3) EU <- data.frame(EuStockMarkets) with(EU, plot(DAX, CAC, col=col2, type="h", ylim=c(0,6000))) par(new=TRUE) with(EU, plot(DAX, FTSE, col=col1, type="h", ylim=c(0,6000))) The density of the red plot around 2000 completely obscures the blue plot behind it. What I would like to do is plot both plots in solid colors, then alpha the entire thing, and then overlay them. Or some other method that achieves a comparable result. Thanks ______________________________________________ [hidden email] mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. |
Interesting problem.
I would discretize the x-values and interleave them. Lines from one dataset still overlap, so you see high- density and low-density regions, but lines from the other dataset are drawn into the interval. Like so: interleave <- function(x, MIN, MAX, N, nChannel = 2, channel) { isp <- seq(MIN, MAX, length.out = N + 1) # interleave support points offset <- ((isp[2] - isp[1]) / nChannel) * (channel - 1) # offset for channel # round x to the nearest support point and add the channel specific offset x <- isp[round(as.numeric(cut(x, breaks = N)))] + offset return(x) } xi <- min(EU$DAX) xa <- max(EU$DAX) plot(interleave(EU$DAX, MIN=xi, MAX=xa, N=130, channel=1 ), EU$CAC, col = "#6600EE07", type = "h", ylim = c(0,6000), xlab = "DAX") points(interleave(EU$DAX, MIN = xi, MAX = xa, N = 130, channel = 2 ), EU$FTSE, col = "#EE000007", type = "h") Cheers, B. > On 2018-05-31, at 16:56, Ed Siefker <[hidden email]> wrote: > > I have two chromatograms I want plotted on the same axes. > I would like the plots to be transparent, so the first chart is > not obscured. > > I have tried adjustcolor(..., alpha.f=0.3), the problem is that > my chromatogram is so dense with datapoints that they > overlap and the entire graph just ends up a solid color. The > second histogram still obscures the first. > > Consider this example: > > > col1 <- adjustcolor("red", alpha.f=0.3) > col2 <- adjustcolor("blue", alpha.f=0.3) > EU <- data.frame(EuStockMarkets) > with(EU, plot(DAX, CAC, col=col2, type="h", ylim=c(0,6000))) > par(new=TRUE) > with(EU, plot(DAX, FTSE, col=col1, type="h", ylim=c(0,6000))) > > The density of the red plot around 2000 completely obscures the blue > plot behind it. > > What I would like to do is plot both plots in solid colors, then alpha > the entire thing, and then overlay them. Or some other method that > achieves a comparable result. > Thanks > > ______________________________________________ > [hidden email] mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. ______________________________________________ [hidden email] mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. |
In reply to this post by Ed Siefker
Hi
Here is one way to do it ... col1 <- "red" col2 <- "blue" EU <- data.frame(EuStockMarkets) with(EU, plot(DAX, CAC, col=col2, type="h", ylim=c(0,6000))) par(new=TRUE) with(EU, plot(DAX, FTSE, col=col1, type="h", ylim=c(0,6000))) ## Convert 'graphics' to 'grid' library(gridGraphics) grid.echo() ## grid.ls(print=grobPathListing, viewports=TRUE) ## Rasterize spikes library(rasterize) downViewport("graphics-window-1-1") grid.rasterize("graphics-plot-1-spike-1") upViewport(0) downViewport("graphics-window-2-1") grid.rasterize("graphics-plot-2-spike-1") upViewport(0) ## Apply alpha adjustment to rasterized spikes spike1 <- as.matrix(grid.get("graphics-plot-1-spike-1")$raster) alphaSpike1 <- adjustcolor(spike1, alpha=.3) dim(alphaSpike1) <- dim(spike1) grid.edit("graphics-plot-1-spike-1", raster=as.raster(alphaSpike1)) spike2 <- as.matrix(grid.get("graphics-plot-2-spike-1")$raster) alphaSpike2 <- adjustcolor(spike2, alpha=.3) dim(alphaSpike2) <- dim(spike2) grid.edit("graphics-plot-2-spike-1", raster=as.raster(alphaSpike2)) ... though that may not be the best way and may just reflect what I have been thinking about recently ... https://www.stat.auckland.ac.nz/~paul/Reports/rasterize/rasterize.html Paul On 01/06/18 08:56, Ed Siefker wrote: > I have two chromatograms I want plotted on the same axes. > I would like the plots to be transparent, so the first chart is > not obscured. > > I have tried adjustcolor(..., alpha.f=0.3), the problem is that > my chromatogram is so dense with datapoints that they > overlap and the entire graph just ends up a solid color. The > second histogram still obscures the first. > > Consider this example: > > > col1 <- adjustcolor("red", alpha.f=0.3) > col2 <- adjustcolor("blue", alpha.f=0.3) > EU <- data.frame(EuStockMarkets) > with(EU, plot(DAX, CAC, col=col2, type="h", ylim=c(0,6000))) > par(new=TRUE) > with(EU, plot(DAX, FTSE, col=col1, type="h", ylim=c(0,6000))) > > The density of the red plot around 2000 completely obscures the blue > plot behind it. > > What I would like to do is plot both plots in solid colors, then alpha > the entire thing, and then overlay them. Or some other method that > achieves a comparable result. > Thanks > > ______________________________________________ > [hidden email] mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > -- Dr Paul Murrell Department of Statistics The University of Auckland Private Bag 92019 Auckland New Zealand 64 9 3737599 x85392 [hidden email] http://www.stat.auckland.ac.nz/~paul/ ______________________________________________ [hidden email] mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. |
Free forum by Nabble - Free Resume Builder | Edit this page |