0

I'm performing Descriptive analysis in Excel these days. But being a R learner i want to reproduce (approx.) the Excel graphics in R by using R's own coding, packages, etc. Here is an example of data: dummy data

and Excel Graph is

Excel output of above data

Being a beginner at learning of R my question is pretty simple: "How to produce this excel graph in R by using base plotting, lattice or ggplot2 whichever is appealing?" Any help would be highly appreciated!!!

Community
  • 1
  • 1
  • 1
    this (http://www.inside-r.org/packages/cran/ggthemes/docs/theme_excel) should help you started – MLavoie May 18 '16 at 17:15
  • 1
    Would you be able to post your data with a data set that is easy to read into R? Check out this [post](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example?rq=1) for suggestions how to do this. – Richard Erickson May 18 '16 at 18:38

1 Answers1

1

Your question is a multi-part question depending upon which elements of the plot are important. Here is a method to reproduce this figure using ggplot2.

First, I create a reproducible dataset:

df <- data.frame(
Group1 = factor(rep(c("A", "Fially", "AC"), each = 3),  
    levels = c("A", "Fially", "AC")),
Group2 = factor(c("B", "GGF", "Kp"), 
    levels = c(c("B", "GGF", "Kp"))),
Value = c(100, 5, 6, 200, 42, 21, 300, 80, 15)
)

Note that you will need to reorder your factors (see Reorder levels of a factor without changing order of values for more help with this if you need it).

Second, I plot the data using ggplot2 using a bar-plot (see the documentation here).

library(ggplot2)
ggOut <- ggplot(data = df, aes(x = Group1, 
                y = Value, fill = Group2)) +
         geom_bar(stat="identity", position="dodge") +
         theme_bw() + 
         ylab("") +
         xlab("") + 
         scale_fill_manual(name = "", 
                           values = c("red", "blue", "black")) 

print(ggOut)
ggsave(ggOut)

This code gives you this figure: enter image description here

To change the legend, I followed this guide.

Community
  • 1
  • 1
Richard Erickson
  • 2,568
  • 8
  • 26
  • 39