0

I have been working on a continuous data set that when plotted with geom_density (ggplot2) will have data points cut off when using scale_x_continuous. The great thing is that xlim() displays the data just as I need it! Only problem is that xlim seems to eliminate the ability to change the axis tick mark labels. So when my Z-score density plot needs to show every tick mark from -3 to 3, it shows data within that range, but does not display the tick marks at those points, as seen in 1.

What would be a function that lets me alter the axis tick marks?

UPDATE: this is what: scale_x_continuous(breaks = pretty(a_tubulin_data$Z.Scores, n = 9)) + coord_cartesian(xlim=c(-3,3))

outputs as seen in 2

  • Have you try to add `coord_cartesian(xlim = c(-3,3) + scale_x_continuous(breaks = seq(-3,3,length.out = 7))` ? – dc37 Apr 18 '20 at 04:15

1 Answers1

0

Are you looking for something like this ?

df <- data.frame(x = rnorm(100,0,1.5))

library(ggplot2)

ggplot(df,aes(x = x))+
  geom_density()+
  coord_cartesian(xlim = c(-3,3))+
  scale_x_continuous(breaks = c(-3,-2,-1,0,1,2,3))

enter image description here

dc37
  • 15,840
  • 4
  • 15
  • 32
  • I've used coord_cartesian(c(-3,3)) + scale_x_continuous however it does something even weirder: it extends the graph tick marks like I want, however cuts the plot at -2 and 2. data definitely extends farther past that. thats why I was looking for an alternate method other than scale_x_continuous, it seems to be where the problem lies – Jonah_huggins Apr 18 '20 at 13:39
  • Ok, if you are using the example I provided, does it work for you ? So, please provide a reproducible example of your dataset and the code you have used (see this link: https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) – dc37 Apr 18 '20 at 17:14