Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201945

Black bar on Y-axis when using scale_x_log10

$
0
0

I’m working on a plot using ggplot2 where I have the data in bins, but I’m having some issues with the graphics.

The issue is this: I wanted to add tick marks to the bottom of my x axis as I currently have the axis in log-scale. I have no problem with generating the plot, but once I add tick marks to it, I also get this thick black bar in the left-hand corner thick black bar in the left-hand corner.

I have the feeling that the issue with the plotting has to do with annotation_logticks(), as when I remove that section of the code, the thick bar goes away the thick bar goes away. I tried changing the limits of scale_x_log10() to avoid the bar, but that didn't do anything

Any suggestions for showing the tick marks on the x-axis while avoiding that bar?

Here is the code I've used to generate the plot and some dummy data (sorry that it's so long!)

I'm not sure if this is useful, but I'm using R version 3.5.3, RStudio version 1.1.463, ggplot2 version 3.2.1 and scales version 1.0.0

library(ggplot2)
library(scales)

df = structure(list(`Size (µm)` = c(0.5, 0.5, 1, 1, 3, 3, 5, 5, 7, 
7, 9, 9, 20, 20, 0.5, 0.5, 1, 1, 3, 3, 5, 5, 7, 7, 9, 9, 20, 
20), `C/dlogd` = c(0, 200, 200, 600, 600, 800, 800, 400, 400, 
300, 300, 150, 150, 0, 0, 205, 205, 605, 605, 805, 805, 405, 
405, 305, 305, 155, 155, 0), `+s` = c(0, 250, 250, 650, 650, 
850, 850, 450, 450, 350, 350, 200, 200, 0, 0, 305, 305, 705, 
705, 905, 905, 505, 505, 405, 405, 255, 255, 0), `-s` = c(0, 
150, 150, 550, 550, 750, 750, 350, 350, 250, 250, 100, 100, 0, 
0, 105, 105, 505, 505, 705, 705, 305, 305, 205, 205, 55, 55, 
0), Sampling = c("A", "A", "A", "A", "A", "A", "A", "A", "A", 
"A", "A", "A", "A", "A", "B", "B", "B", "B", "B", "B", "B", "B", 
"B", "B", "B", "B", "B", "B")), row.names = c(NA, -28L), class = c("tbl_df", 
"tbl", "data.frame"))

ggplot(d, aes(x=  `Size (µm)`)) + 
geom_line(aes(y = `C/dlogd`), size = 1.5) + 
geom_line(aes(y =  `+σ`), linetype = "twodash", color = "red") +
geom_line(aes(y =  `-σ`), linetype = "dashed" , color = "blue") +
geom_point(aes(y =  `+σ`), color = "red") +
geom_point(aes(y = `C/dlogd`)) +
geom_point(aes(y =  `-σ`), color = "blue") +
scale_x_log10(limits = c(0.4,25)) + 
facet_wrap(~Sampling, scales = "free") +
theme_bw() 

Thanks for your help!


Viewing all articles
Browse latest Browse all 201945

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>