Order bar graph by value ggplot2

Shery

My df:

summary2

Source: local data frame [4 x 2]

      mean      Patch
     (dbl)     (fctr)
1 3.210293   Scotland
2 3.555884         UK
3 3.883458   UK North
4 4.003116 Department

The df is already ordered by mean but when I draw bar plot, it messes up the order.

Here is the code:

    ggplot(summary2,aes(x=Patch,y=mean, fill = Patch)) +
  geom_bar(colour="black",stat = "identity") 

Any ideas how to put it in ordered bar graph?

Vandenman

A solution that's completely inspired by this post:

df = read.table(header = TRUE, 
text = 'mean      Patch
1 3.210293   Scotland
2 3.555884         UK
3 3.883458   UKNorth
4 4.003116 Department')

ggplot(df,aes(x=Patch,y=mean, fill = Patch)) +
  geom_bar(colour="black",stat = "identity") + 
  scale_x_discrete(limits = df$Patch[order(df$mean)])

There are also other solutions mentioned via reordering.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Order Bars in ggplot2 bar graph

Bar graph with error bar in ggplot2

ggplot2: Date range bar graph

ggplot2 stacked bar graph in which every value is a group/color

Order stacked ggplot2 percentage bar plot by y continuous value - repost

How to order stacked bar plot x categories by value of one of the fill categories in ggplot2/R

Define order of bars in ggplot2-generated stacked bar graph

ggplot2: geom_bar(); how to alternate order of fill so bars are not lost inside a bar with a higher value?

How to order the bar graph in plotly even where a value is duplicated?

ggplot bar graph - changing colour for value of y

Add text to bar graph ggplot2 (asterisks for significance)

Why is some data missing in ggplot2 stacked bar graph?

plotting two variables on bar graph using ggplot2

Add count labels to clustered bar graph ggplot2

Question about ggplot2 bar graph transformation method

ggplot2: Bar graph with vertical columns for continuous data

Turning data into horizontal bar graph with ggplot2

Need to Draw a Bar Graph ( in percentile manner ) in ggplot2

Showing significance relationships in a ggplot2 bar graph

Add line to double bar graph in ggplot2

plotting two error bar and a point graph in ggplot2

Line graph over Bar Chart ggplot2 R

ggplot2 stacked bar graph using rows as datapoints

Generate a bar graph using ggplot2 and dplyr in R

Why is my ggplot2 bar graph not displaying?

sorted R ggplot2 bar graph grouped by month and person

Customising X-axis on Stacked Bar Graph GGplot2

ggplot2 bar graph with statistics (apoptosis/necrosis assay)

R: How to graph a data table into a specific order with ggplot2?