0

FIXED - I COULD NOT COUNT PROPERLY Thanks for the help in the comments

I've tried to create a histogram with ggplot and color it by group. The problem arises when it shows 30 values for one group but only 28 for the other group. I've tried changing the x-axis, but the values wont appear.

I use the excel reader.

Heres the code i use:

p14 <- ggplot(SamletTabel14, 
  aes(x=Antal, fill=factor(Kondition, 
    levels = c("Uden mundbind", "Med mundbind")))) +
geom_histogram(position="identity", binwidth = 1, alpha=0.5)

p14 <- p14 + 
  theme(text = element_text(size=15), 
    axis.text.x = element_text(size = 10), 
    axis.text.y = element_text(size = 10)) + 
  ggtitle("Histogram antal korrekt - Overordnet")+ 
  theme(plot.title = element_text(hjust=0.5))

p14 <- p14 + 
  ylab("Frekvens")  +  
  scale_x_continuous(limits = c(18,36), 
    breaks = c(18,20, 22, 24, 26, 28, 30, 32, 34, 36), 
    labels = c(18,20, 22, 24, 26, 28, 30, 32, 34, 36))

p14 <- p14 + labs(fill="Kondition")

p14

R says that the data is 60 observations of three variables. So why doesnt it plot it?

Edit: Asked for data as dput():

SamletTabel14 <- read_excel("C:/Users/jacob/Desktop/Data/SamletTabel.xlsx", sheet = "Ark15")

dput(as.data.frame(SamletTabel14))

structure(list(ID = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 
13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 
29, 30, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 
17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30), Antal = c(32, 
29, 30, 29, 32, 26, 31, 34, 27, 35, 31, 27, 28, 28, 30, 32, 32, 
35, 27, 34, 32, 34, 31, 33, 32, 31, 32, 33, 34, 32, 25, 28, 22, 
23, 29, 26, 28, 29, 23, 31, 23, 27, 22, 21, 29, 29, 27, 28, 22, 
27, 28, 30, 27, 30, 31, 23, 26, 29, 30, 29), Kondition = c("Uden mundbind", 
"Uden mundbind", "Uden mundbind", "Uden mundbind", "Uden mundbind", 
"Uden mundbind", "Uden mundbind", "Uden mundbind", "Uden mundbind", 
"Uden mundbind", "Uden mundbind", "Uden mundbind", "Uden mundbind", 
"Uden mundbind", "Uden mundbind", "Uden mundbind", "Uden mundbind", 
"Uden mundbind", "Uden mundbind", "Uden mundbind", "Uden mundbind", 
"Uden mundbind", "Uden mundbind", "Uden mundbind", "Uden mundbind", 
"Uden mundbind", "Uden mundbind", "Uden mundbind", "Uden mundbind", 
"Uden mundbind", "Med mundbind", "Med mundbind", "Med mundbind", 
"Med mundbind", "Med mundbind", "Med mundbind", "Med mundbind", 
"Med mundbind", "Med mundbind", "Med mundbind", "Med mundbind", 
"Med mundbind", "Med mundbind", "Med mundbind", "Med mundbind", 
"Med mundbind", "Med mundbind", "Med mundbind", "Med mundbind", 
"Med mundbind", "Med mundbind", "Med mundbind", "Med mundbind", 
"Med mundbind", "Med mundbind", "Med mundbind", "Med mundbind", 
"Med mundbind", "Med mundbind", "Med mundbind")), row.names = c(NA, 
-60L), class = "data.frame")
Blobber
  • 1
  • 1
  • How should we know without your data? See [how to make a minimal reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) – stefan Nov 28 '20 at 10:49
  • One issue could be that some values fall outside of the limits you specified. Therefore you could try without `limits = c(18,36)`. – stefan Nov 28 '20 at 10:50
  • R doesnt give the error without it, but still only shows 28 datapoints for the one group :( The smallest value is 26 and the biggest is 35 for the mentioned group – Blobber Nov 28 '20 at 10:55
  • Are there any NAs in your data? You said it's 60 observations, but your picture only has 30... Also, can you post your data with `dput()` instead of a picture? – Érico Patto Nov 28 '20 at 11:31

0 Answers0