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

How to define different y-axis breaks for different facets in ggplot2?

$
0
0

I am doing a plot with 5 facets all in 1 column (one above the other). Each facet has a different scale, so I would like to control them independently.

I found many posts about the usage of facet_grid() and facet_wrap(scales="free") which helped me getting to where I'm now. The problem I'm facing now is that I want to control the breaks=... for each facet independently.

I am attaching the code and the generated plot below. What I'm after, is to have the following breaks:

A: breaks=seq(0,100,100)
B: breaks=seq(0,100,100)
C: breaks=seq(0,50,50)
D: breaks=seq(0,50,50)
E: breaks=seq(0,1,1)

Here is the code I'm using:

P1 = (
ggplot(data=Melt_jacc)
+ theme(plot_title=element_text(family="sans", face="bold", 
                colour='#261A1A', size=11),
axis_title_x=element_text(  family="sans", face="plain",
                colour='#261A1A', size=8),
axis_title_y=element_text(  family="sans", face="plain",
                colour='#261A1A', size=8),
axis_text_x=element_text(family="sans", face="plain", colour='#261A1A', size=8),
axis_text_y=element_text(family="sans", face="italic", colour='#261A1A', size=8),
legend_text=element_text(family="sans", face="italic", colour='#000000', size=8),
legend_title=element_text(family="sans", face="plain", colour='#000000', size=8),
panel_background=element_rect(fill='#DCDCDC', colour='#DCDCDC'),
aspect_ratio=0.10)
+ geom_path(aes(x="W_start", y="Value"))
+ xlab("")
+ ylab("")
+ scale_x_continuous(breaks=[i for i in range(0, int(round(max_w_start, 0))+1, 10)])
+ facet_wrap("~Feature", ncol=1, nrow=5, scales="free")

Here is the generated plot: enter image description here

Thank you all for the help, in advance!


Viewing all articles
Browse latest Browse all 201945

Trending Articles



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