How to put non-numerical data from one column table into ggplot2? or anything?

Hi, so here is a very basic code from me:

Data <- read.csv("QuestionaireData_CityTrips_csv.csv")
Data_nat <- Data[,459]
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()

I wouldn't subset the dataframe but instead use it as is. See if this helps. If not create a reprex and we can work with your data (see here: FAQ: How to do a minimal reproducible example ( reprex ) for beginners)

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)))

#>   sex weight
#> 1   F     49
#> 2   F     56
#> 3   F     60
#> 4   F     43
#> 5   F     57
#> 6   F     58

# 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)) + 

# Change colors
p<-ggplot(df, aes(x=weight)) + 
  geom_histogram(color="black", fill="white")
#> `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

Created on 2020-11-18 by the reprex package (v0.3.0)

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:

You could try dplyr count()
Examples included...