How to recreate an Excel line graph with a table with ggplot

438 views
Skip to first unread message

Timothy Lau

unread,
Apr 29, 2015, 9:08:19 PM4/29/15
to ggp...@googlegroups.com

How do should I go about recreating this graph in ggplot?


Brandon Hurr

unread,
Apr 29, 2015, 9:43:49 PM4/29/15
to Timothy Lau, ggp...@googlegroups.com
Tim

You're gonna have a difficult time getting the exact same output but you can get close with the following.

Get the data into an R dataframe.
Create the top plot with geom_point, geom_line and geom_text.
Then create a table with grid and put the two together with the gridExtra package.

I remember other people doing something similar so search stackoverflow and the archives here for help.

If you're stuck, supply a dataset in dput() format and your attempt at getting started.

B
On Wed, Apr 29, 2015 at 18:08 Timothy Lau <timoth...@gmail.com> wrote:

How do should I go about recreating this graph in ggplot?


--
--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: https://github.com/hadley/devtools/wiki/Reproducibility
 
To post: email ggp...@googlegroups.com
To unsubscribe: email ggplot2+u...@googlegroups.com
More options: http://groups.google.com/group/ggplot2

---
You received this message because you are subscribed to the Google Groups "ggplot2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ggplot2+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

John Kane

unread,
May 3, 2015, 9:11:57 PM5/3/15
to ggp...@googlegroups.com
Blast, only pasted half the code. Here it is in a form that might even work. Apologies.

library(RGraphics)
library(gridExtra)
library(ggplot2)

chartjunk  <-  data.frame(xx = 16:35,
                  act = c( 1,5,8,42,192,171,143,114,102,133,100,94,69,69,51,34,18,12,7,1),
                                dg = c(0,1,1,3,12,20,17,18,21,38,29,34,30,28,22,19,11,9,6,1))


char1  <-   melt(chartjunk, id.vars = c("xx"))
g1 <-  ggplot(char1,  aes(xx, value, colour = variable )) +
             geom_line() + geom_g1  point()
g2 <- tableGrob(chartjunk)

grid.arrange(g1, g2, ncol=2)


On Wednesday, April 29, 2015 at 9:08:19 PM UTC-4, Timothy Lau wrote:

John Kane

unread,
May 4, 2015, 1:33:43 PM5/4/15
to ggp...@googlegroups.com

At this rate I'll never get it right.1 
Add  library(plyr) to the code
Apologies again.

jrk

On Wednesday, April 29, 2015 at 9:08:19 PM UTC-4, Timothy Lau wrote:

jwd

unread,
May 6, 2015, 12:19:58 PM5/6/15
to ggp...@googlegroups.com
On Wed, 29 Apr 2015 18:08:19 -0700 (PDT)
Timothy Lau <timoth...@gmail.com> wrote:

>
>
> How do should I go about recreating this graph in ggplot?
> <https://lh3.googleusercontent.com/-s_Aj4i1PyZ4/VUF_3kUJRzI/AAAAAAAB7pU/A0MvwGlUyJY/s1600/great%2Bgraph.PNG>
>

Ideally, you shouldn't. The chart is misleading, and the table is
likewise for any reader that doesn't look closely at the numbers.
There is a strong positive correlation between ACT score and the number
of degrees awarded as a proportion of those tested and receiving that
score that is not apparent on the chart.

JDougherty

Reply all
Reply to author
Forward
0 new messages