1

I am trying to plot a multiple line graph to represent a frequency table such that under the graph along the x-axis, it also gives me the actual values for each of the series in a table. For e.g.:

if there are 3 values to plot on x-axis - 1,2,3;
frequencies for series A are 1 - 2 times, 2 - 5 times, 3 - 7 times;
frequencies for series B are 1 - 7 times, 2 - 5 times, 3 - 3 times.

Then under the x-axis of the line graph, table is formed such that frequencies of both series are listed under each x-value.

While I can create multi-line graph using ggplot I am not sure how to add the table.

2
  • 3
    A reproducible example would be great, as well as what you have tried so far (e.g. the ggplot code). So you are trying to "plot" a frequency table underneath the x axis as part of the graph? Any reason why you wouldn't have a (picture) graph, and the (text) table underneath? Commented Jul 16, 2015 at 1:39
  • That's because I was writing a statistical abstract which has many sets of graph and tables. And that was a great way to fit everything neatly without creating a long scroll in the document. Also excel has an option of creating a line graph in which you can add the freq. table in the same graph. So I wondered if that kind of an effect was possible in R. Commented Jul 17, 2015 at 2:20

1 Answer 1

3

You can do something like this:

df <- data.frame(group = c("A", "A", "A", "B", "B", "B"), 
                 x = c(1, 2, 3, 1, 2, 3), 
                 y = c(2, 5, 7, 7, 5, 3))
library(ggplot2)
plt <- ggplot(data = df, aes(x = x, y = y, group = group, colour = group)) +
  geom_line() +
  geom_point()
tbl <- tableGrob(t(df), rows = NULL,
                 theme = ttheme_minimal())
# Plot and table together
library(gridExtra)
grid.arrange(plt, tbl,
             nrow = 2,
             as.table = TRUE,
             heights = c(3,1))

enter image description here

Sign up to request clarification or add additional context in comments.

1 Comment

Great! @user3816784 if this or any answer has solved your question please consider accepting it by clicking the check-mark. This indicates to the wider community that you've found a solution and gives some reputation to both the answerer and yourself. There is no obligation to do this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.