Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
back-to-back bar charts
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  9 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Patrick Wustmann  
View profile  
 More options Sep 24, 7:13 am
From: Patrick Wustmann <wustm...@tcd.ie>
Date: Thu, 24 Sep 2009 12:13:56 +0100
Local: Thurs, Sep 24 2009 7:13 am
Subject: back-to-back bar charts
Hi folk,

does anyone know how to create a back-to-back bar chart with ggplot2?

For anyone who don't know what I am talking about, have a look on a
recent paper from the EU (sorry for posting a link, but i think its
best to see an example):

http://ec.europa.eu/agriculture/publi/map/02_09.pdf

I'd like to create plots like the graphs 5,6,18 in the paper.

Moreover due to space constraints I need to draw a second information
in one plot (see also the graphs in the paper). I know 2 y-axis plots
is not good but sometimes it is better to have eye catching plots with
lots of information in it rather than multiple plots :). Is there a
way to do  such things with ggplot2?

Thank you very much.

Patrick


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
baptiste auguie  
View profile  
 More options Sep 24, 7:31 am
From: baptiste auguie <bapt4...@googlemail.com>
Date: Thu, 24 Sep 2009 13:31:33 +0200
Local: Thurs, Sep 24 2009 7:31 am
Subject: Re: back-to-back bar charts
Hi,

Would that be similar to these examples?

http://learnr.wordpress.com/2009/06/01/ggplot2-positioning-of-barplot...

baptiste

--
_____________________________

Baptiste Auguié

School of Physics
University of Exeter
Stocker Road,
Exeter, Devon,
EX4 4QL, UK

http://newton.ex.ac.uk/research/emag
______________________________


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Patrick Wustmann  
View profile  
 More options Sep 24, 8:16 am
From: Patrick Wustmann <wustm...@tcd.ie>
Date: Thu, 24 Sep 2009 13:16:26 +0100
Local: Thurs, Sep 24 2009 8:16 am
Subject: Re: back-to-back bar charts
Hi,

thanks for the reply, No, not really unfortunately. These bars are not
back to back. I need to have two bars on one line 'pointing' in
opposite directions to depict a negative and a positive value on the
same time.

Patrick

2009/9/24 baptiste auguie <bapt4...@googlemail.com>:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Harlan Harris  
View profile  
 More options Sep 24, 8:25 am
From: Harlan Harris <harlan.har...@gmail.com>
Date: Thu, 24 Sep 2009 05:25:13 -0700 (PDT)
Local: Thurs, Sep 24 2009 8:25 am
Subject: Re: back-to-back bar charts
I'd think you'd want to use geom_rect (http://had.co.nz/ggplot2/
geom_rect.html) with a df like:

id year com.imp com.exp int.imp int.exp fin.imp fin.exp conf.imp
conf.exp bal

and position_stack(). Plus the geom_line() as a separate layer. Oh,
wait, you might have to manually add the data together -- I'm not sure
if position_stack() works with geom_rect() in the right way...

And yeah, I'd find some other way to do the plot than using a second Y
axis. Probably just a small (short but wide) graph of the second data
set on a separate graph, above or below the main graph. I'm not sure
why they're plotted together on Fig 18 anyway -- the two lines are not
very correlated once you get rid of the linear trend...

 -Harlan

On Sep 24, 8:16 am, Patrick Wustmann <wustm...@tcd.ie> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Andreas Christoffersen  
View profile  
 More options Sep 24, 8:48 am
From: Andreas Christoffersen <achristoffer...@gmail.com>
Date: Thu, 24 Sep 2009 14:48:21 +0200
Local: Thurs, Sep 24 2009 8:48 am
Subject: Re: back-to-back bar charts

Hi Patrick,

Is it not simple a stacked barchart with imports being plottet as negative
values? I dont have time to try it out in ggplot right now - but maybe
later. Guess you have to use stat_identity someway.

It's not easy to read though - that kind of chart. Maybe try with
facet_grid(.~import_export)


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Harlan Harris  
View profile  
 More options Sep 24, 11:45 am
From: Harlan Harris <harlan.har...@gmail.com>
Date: Thu, 24 Sep 2009 08:45:05 -0700 (PDT)
Local: Thurs, Sep 24 2009 11:45 am
Subject: Re: back-to-back bar charts
Hm, poking at this a little... I actually like the two-sided bar
charts as a visualization with the surplus/deficit in the middle.
Here's what I came up with as a first stab:

df <- expand.grid(year=seq(1999,2008),
        type=c("Commodities", "Intermediate", "Final Products",
"Confidential"),
        dir=c("Imports", "Exports"))

df$Value = runif(nrow(df), 5, 30) * ifelse(df$dir=="Imports", -1, 1)

library("ggplot2")

p <- ggplot(df, aes(x=year, y=Value, fill=type)) +
        geom_bar(stat="identity", data=subset(df, dir=="Imports")) +
        geom_bar(stat="identity", data=subset(df, dir=="Exports"))

df.m <- melt(df, id=c("type", "year", "dir"))
df.trade <- cast(df.m, year ~ ., sum)
names(df.trade) <- c("year", "Value")

p <- p + geom_line(data=df.trade, aes(fill=NULL), color="black",
size=2)

The aes(fill=NULL) is required to prevent a decidedly unhelpful eval
error. For reasons I don't yet understand, the line geom crashes if
you don't override the fill=type aesthetic. And there's no legend for
the Trade line. This may be a case where, if you're generating graphs
for publication, some post-hoc editing may be valuable...

Also, the code gives the following warning, despite working fine:

Warning message:
Stacking not well defined when ymin != 0

Anyone know why it would complain in this case?

 -Harlan

On Sep 24, 8:48 am, Andreas Christoffersen <achristoffer...@gmail.com>
wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Learning R Blog  
View profile  
 More options Sep 24, 2:55 pm
From: Learning R Blog <rlea...@gmail.com>
Date: Thu, 24 Sep 2009 11:55:17 -0700 (PDT)
Local: Thurs, Sep 24 2009 2:55 pm
Subject: Re: back-to-back bar charts
I came up with pretty much the same solution - and made a quick
blogpost about it as well, also showing the faceting option.

http://learnr.wordpress.com/2009/09/24/ggplot2-back-to-back-bar-charts/

On Sep 24, 7:45 pm, Harlan Harris <harlan.har...@gmail.com> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Patrick Wustmann  
View profile  
 More options Oct 9, 1:06 pm
From: Patrick Wustmann <wustm...@tcd.ie>
Date: Fri, 9 Oct 2009 18:06:34 +0100
Local: Fri, Oct 9 2009 1:06 pm
Subject: Re: back-to-back bar charts
Thank you very much for that! Saved me a lot of time.

Patrick

2009/9/24 Learning R Blog <rlea...@gmail.com>:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
James Howison  
View profile  
 More options Oct 11, 4:12 pm
From: James Howison <ja...@freelancepropaganda.com>
Date: Sun, 11 Oct 2009 16:12:21 -0400
Local: Sun, Oct 11 2009 4:12 pm
Subject: Re: back-to-back bar charts
btw, that is one awesome blog post.  Thanks!

On Sep 24, 2009, at 14:55, Learning R Blog wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google