Home > Mobile >  Force the origin of start at 1 in GGstream plot
Force the origin of start at 1 in GGstream plot

Time:11-01

I would like my Y axis to start at 1 on the x-axis, my first data point, and end at 3, my last data point, at the moment there is a cell on each side of my plot making the plot look like it starts in the middle of the graph. My x axis is categorical

I've tried fiddling with all the functions in the GGstream PDF (there aren't that many). I am wondering if the fix lays within the "mapping" function but I can't seem to get it to work, the PDF gives no indication how to use it, with the only option as "NULL". I have tried using GGPlot2 language such as

  • scale_x_discrete(limits=c("1", "2" "3")

and

  • coord_cartesian(xlim = c(1,3))

But I still have this extra "padding" around my data

Reprex:

library(ggstream)

Date <- c("1", "1", "2", "2", "3", "3")
Taxon <- c("Turtle", "Invert", "Turtle", "Invert", "Turtle", "Invert")
Freq <- c("100", "50", "50", "2", "35", "0")

stream <- data.frame(Date, Taxon, Freq)

stream$Date <- as.factor(stream$Date)

ggplot(stream, aes(x = Date, y = Freq, fill = Taxon))  
geom_stream (extra_span = 0.8, bw = 1, sorting = c( "onset"), type = "ridge")

CodePudding user response:

Add coord_cartesian(expand = FALSE) to turn off default expansion of limits.

CodePudding user response:

You can either use scale_x_discrete(expand = c(0, 0)) or coord_cartesian(expand = FALSE) to remove padding around your plot. Here is the documentation.

  • Related