Hist/ Histogram fail

Hello,

I tried to make a histogram form the nummers i got out of my data set.
I get an error with that the number is not a numeric.

i made a screen shot to. maby the situation is more clear.

I see two problems:

  1. You are passing the entire tibble Strategy1 to the hist() function but it is expecting a vector of values. You would need to use hist(Strategy1$Total_EU_Sales), but there is a second problem.
  2. Strategy1 contains only a single value, the sum of all EU_Sales after the filtering. You can see this at the top right of the screen where Strategy1 is described as 1 obs. of 1 variable. A histogram of one point is not informative.

I dont think a histogram of a single summary value makes anysense but, you have omitted to identify the column of the data.frame to use
hist(Strategy1$Total_EU_Sales)

i tough to do it this way:

Simulation10 <- videogames %>%
filter(Genre == "Simulation") %>%
filter(Platform %in% c("NES", "SNES" , "N64", "Wii", "WiiU", "GB", "GBA", "GC", "3DS", "DS", "3DS")) %>%
summarise(Total_EU_Sales = sum(EU_Sales))
print (Simulation10) #57.49

Sports11 <- videogames %>%
filter(Genre == "Sports") %>%
filter(Platform %in% c("NES", "SNES" , "N64", "Wii", "WiiU", "GB", "GBA", "GC", "3DS", "DS", "3DS")) %>%
summarise(Total_EU_Sales = sum(EU_Sales))
print (Sports11) #123.87

Strategy12 <- videogames1 %>%
filter(Genre == "Strategy") %>%
filter(Platform %in% c("NES", "SNES" , "N64", "Wii", "WiiU", "GB", "GBA", "GC", "3DS", "DS", "3DS")) %>%
summarise(Total_EU_Sales = sum(EU_Sales))
print (Strategy12) #8.39

hist(Strategy12,Sports11,Simulation10$Total_EU_Sales)

so i have more input for the histogram.. but my way is not working :frowning:

I think that you conceptually want a histogram, but hist() does binning for you and plotting, if you want to plot your own binned up numbers you would use barplot() or geom_col() of ggplot2

library(tidyverse)

(mydf<- tibble(label=c("A","B","C"),
              value=c(3,1,2)))

#option 1
barplot(formula= value ~ label,
        data=mydf)
#option 2
ggplot(data=mydf,mapping=aes(x=label,y=value)) + 
  geom_col()

This is not working for me.

i tried this one:
counts <- table(videogames1$EU_Sales)
barplot(counts, main="Verkoop",
xlab="Verkoop cijfers Eu sales videogames")

But what is want is these nummers in a histogram or a barplot:

1. Action = 114.8

2. Adventure = 24.77

3. Fighting = 20.3

4. Misc = 122.82

5. Platform = 122.61

6. Puzzle = 43.44

7. Racing = 59.29

8. Role-Playing = 71.36

9. Shooter = 19.67

10. Simulation = 57.49

11. Sports = 123.87

12. Strategy = 8.39

Its hard to help if you dont explain...

you have omitted the formula which is used to tell barplot what to use as a value and what to use as a label however first deal with your main problem of constructing a single dataframe with your required labels and values

(to_plot <-  vidgeogames %>%
group_by(Genre) %>%
filter(Platform %in% c("NES", "SNES" , "N64", "Wii", "WiiU",
                     "GB", "GBA", "GC", "3DS", "DS", "3DS")) %>% 
summarise(value= sum(EU_Sales)) %>% rename(label=Genre))

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.