Categories: r, ggplot2

How to indicate y axis does not start from 0 in ggplot?

1 answer

How can I break the the y axis not starting from 0 in my plot? I guess it can't be done with ggplot. Any other solutions?

I want to get this: enter image description here

My ggplot:

ggplot(allEvents %>% dplyr::filter(FixationID>1,FixationID<15), aes(FixationID, Fixation)) +   geom_line(stat="summary", fun.y=mean, position="identity") + theme_bw() + stat_summary(fun.data=mean_se)+      labs (x = "Ordinal fixation number", y = "Fixation duration (s)") +     scale_y_continuous (name="Fixation duration (s) ", limits=c(0.1, 0.4)) +    scale_x_continuous (name="Ordinal fixation number", breaks=c(5,10,15,20)) +    geom_smooth(method=lm) 

Excerpt from my data:

structure(list(Fixation = c(0.383, 0.185, NA, 0.312, NA, 0.328,  NA, 0.259, NA, 0.335), FixationID = c(1, 2, NA, 3, NA, 4, NA,  5, NA, 6)), .Names = c("Fixation", "FixationID"), row.names = c(NA,  10L), class = "data.frame") 

All answers to this question, which has the identifier 61238993

The best answer:

As mentioned by @teunbrand's comment, ggplot2 does not allow for axis breaks, s it is really tricky to get it done.

Alternatively, you can plot your graph in base r plot, and use axis.break function from plotrix package.

(NB: I used between function from dplyr to select the subset of data you are interested by. Your dataset is called df in my example).

library(dplyr)  library(plotrix)  with(subset(df, between(FixationID,2,15)),      plot(x = FixationID, y = Fixation, type = "b", ylim = c(0.1,0.4), pch = 16)) with(subset(df, between(FixationID,2,15)),      abline(lm(Fixation~FixationID),col = "blue")) axis.break(axis = 2, breakpos = 0.1, style="slash") 

enter image description here

Does it answer your question ?

Last questions

how do i remove the switch on my home screen?
how to edit the JS date and time to update atuomatically?
How to utilize data stored in a multidimensional array
Powermockito not mocking URL constructor in URI.toURL() method
Android Bluetooth LE Scanner only scans when phone's Location is turned on in some devices
docker wordpress container can't connect to mysql container
How can I declare a number in java that is more than 64-bits? [duplicate]
Optaplanner solutionClass entityCollectionProperty should never return null error when simple JSON object passed to controller
Anylogic, get the time a pedestrain is in a queue
How do I fix this syntax issue with my .flex file?
Optimizing query in PHP
How to find the highest number of a column and print two columns of that row in R?
Ideas on “Error: Type com.google.firebase.iid.zzav is referenced as an interface from com.google.firebase.messaging.zzd”?
JCIFS SmbFile.exists() and SmbFile.isDirectory() return false when it exists and I can listFiles()
PHP total order
Laravel booking system design
neural net - undefined column selected
How to indicate y axis does not start from 0 in ggplot?
Fragments in backStack
Spinner how to change the data