Reverse Y axis in ggplot and facet

Majed86

I have a data set contains a depth data from 0 - 140 and other columns include some percentages. I plot the data using ggplot and facet and it was great except the zero on the y axis (depth) at bottom of the axis. I want this zero to be at the top of y axis.

this is the data for example:

log <- structure(list(
  Depth = c(5,10,15,20,25,30,35,40,45,50,55, 60,65, 70,75,80, 85,90, 95,100,105,110,
            115,120,125,130,135,140), 
  mic1 =  c(16.93548387,13.55932203, 6.034482759,33.6, 26.8907563, 51.47928994, 
            24.29906542,16.84210526, 26.14379085, 19.72318339,21.77419355,
            53.33333333,50.56179775,19.07514451,27.63819095, 25.6, 23.56687898, 
            19.04761905, 43.33333333,36.30952381,62.45059289,20.43010753,
            32.23140496,16.4021164,47.48201439,48.73646209,17.44186047, 
            39.04109589),  
  mic2 = c(16.93548387, 13.55932203, 6.034482759,33.6, 26.8907563, 51.47928994, 
           24.29906542,16.84210526, 26.14379085, 19.72318339,21.77419355,
           53.33333333,50.56179775,19.07514451,27.63819095, 25.6, 23.56687898, 
           19.04761905, 43.33333333,36.30952381,62.45059289,20.43010753,
           32.23140496,16.4021164,47.48201439,48.73646209,17.44186047, 
           39.04109589)), 
  .Names = c("Depth", "f1", "f2"), row.names = c(NA, 20L), class = "data.frame")

I am using this code to plot them in bars:

logMelt1 <- melt(log, id.vars="Depth")
logm <- ggplot(logMelt1, aes(x=Depth, y=value)) + geom_bar(stat = 'identity') + 
  coord_flip()  + facet_grid( ~ variable, scale ='free_x')
logm

As you can see the Depth axis start from the bottom: enter image description here

I want to know how I can revers the depth axis so the 0 will start at the top?

joran

Maybe try:

logm <- ggplot(logMelt1, aes(x=Depth, y=value)) + 
  geom_bar(stat = 'identity') + 
  scale_x_reverse() +
  coord_flip()  + 
  facet_grid( ~ variable, scale ='free_x')

to reverse the axis?

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

ggplot facet_grid with different y axis scales: reverse axis for a facet panel

Reversing y-axis in an individual ggplot facet

Independent y-axis per nested facet in ggplot

Adjusting y axis limits in ggplot2 with facet and "free" scales

Ordering factors in each facet of ggplot by y-axis value

Dual y-axis while using facet_wrap in ggplot with varying y-axis scale

How to reverse secondary continuous_y_axis in ggplot2

Reverse order of discrete y axis in ggplot2

Reverse secondary y-axis plot with ggplot2

ggplot2 Facet Wrap Reorder by y-axis, Not x-axis

Different x axis for ggplot facet

How can I remove part of y-axis and reverse the axis in ggplot2

How to increase the default y-axis limit in ggplot when scales in facet_wrap() are set to "free"

Sorting Y-axis of barplot based on the decresing value of last facet grid in ggplot2

Change y axis limits for each row of a facet plot in ggplot2

How to define common y-axis limits when using facet_grid() in ggplot2

Facet_wrap and scale="free" unexpectedly centers y-axis at zero in ggplot2

ggplot2 facet wrap: y-axis scale on the first row only

ggplot2 facet_grid create panels on the y-axis

R ggplot facet_wrap with different y-axis labels, one values, one percentages

Is there an R function to get the max y-axis when doing ggplot facet?

ggplot facet grid y axis some values are not visible how adjust grid

How to make y-axis scales same size for each facet in ggplot2?

How to set different y-axis scale in a facet_grid with ggplot?

In ggplot/facet_wrap(), how to marke axis Y have different format

ggplot secondry y axis scale based on data with facet_wrap or grid_arrange

ggplot reverse axis order for factors

Using facet_wrap in ggplot2, how can log and linear y-axis scales be mixed (with appropriate axis text)?

How to reverse axis y predetermined from scale_y_log10? ggplot [repeated]

TOP Ranking

HotTag

Archive