-2

I need help making an histogram from a 3x2 tibble. I averaged the 3 samples in each group (Expt and Ctrl) and now trying to plot their histograms in the same plot. Also, I would like to add a legend that contains the coloring and name of each group.

Getting an error: Error: Aesthetics must be either length 1 or the same as the data (3): y

Tible looks like this. 3x2

control.average exp.average

[-0.01280627, -1.014465]

[99.93987077, 10.009083]

[6.02685326, 3.995733]

library(ggplot2)
# Create Histogram
ggplot(sample.average, aes(x = rownames(sample.average), y = colnames(sample.average))) + geom_histogram()+ stat = "identity"+ position = "dodge"        

1 Answers1

0

I'm not sure what you have in your data frame. This should get you started as well you can do help(ggplot) to read the help manual.

library(ggplot2)
ggplot(df, aes(x = exp.average, y = control.average, fill=factor(index))) + geom_histogram(stat = "identity", position = "dodge") + guides(fill=guide_legend(title="Group")) + labs(x = "Experimenatal", y="Control")

Output

output_dummy

data

df <- structure(list(control.average = c(-0.01280627, 99.93987077, 
6.02685326), exp.average = c(-1.014465, 10.009083, 3.995733), 
    index = c(1, 2, 1)), row.names = c(NA, -3L), class = "data.frame")

Hope it helps.

Community
  • 1
  • 1
deepseefan
  • 3,701
  • 3
  • 18
  • 31