Data <- read.csv("QuestionaireData_CityTrips_csv.csv")
Data_nat <- Data[,459]
table(unlist(Data_nat))
df_nat <- data.frame(Data_nat)
I just would like to visualize this in a table. I've tried with ggplot2, but I got an error that the colSums has to be two-dimensional. Histogram didn't work as well as data in my file is non-numerical. Do you have any ideas how to do it?
Here is some basic code to get a histogram to work with ggplot. As you wil see I have sex and weight in my data and then I proceed to make use of ggplot but within it I specify a aes() followed by geom_histogram()
set.seed(1234)
df <- data.frame(
sex=factor(rep(c("F", "M"), each=200)),
weight=round(c(rnorm(200, mean=55, sd=5), rnorm(200, mean=65, sd=5)))
)
head(df)
#> sex weight
#> 1 F 49
#> 2 F 56
#> 3 F 60
#> 4 F 43
#> 5 F 57
#> 6 F 58
library(ggplot2)
# Basic histogram
ggplot(df, aes(x=weight)) + geom_histogram()
#> `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
# Change the width of bins
ggplot(df, aes(x=weight)) +
geom_histogram(binwidth=1)
# Change colors
p<-ggplot(df, aes(x=weight)) +
geom_histogram(color="black", fill="white")
p
#> `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
Thank you very much for your answer! Unfortunately, I am still not sure how to create a data frame like in your solution. My data frame looks like this: