How to graph categorical variable

Hi,

Example data:

tibble::tribble(
  ~Item, ~Description,
   123L, "something1",
   123L, "something1",
   123L, "something1",
   321L, "something2",
   321L, "something2",
   321L, "something2"
  )

I am trying to graph on x axis the unique descriptions, in this case a separate bar for something1 and something2

And on y axis the count of unique items, in this case bar for both of them should be at one as they each have one item.

This may help


library(tidyverse)

data_set <- tibble::tribble(
  ~Item, ~Description,
  123L, "something1",
  123L, "something1",
  123L, "something1",
  321L, "something2",
  321L, "something2",
  321L, "something2"
)


data_set %>% 
  group_by(Description) %>% 
  summarise(dist_cnt = n_distinct(Item)) %>% 
  ggplot()+
  aes(x = Description , y = dist_cnt) +
  geom_col()

it gives me this error:
image

in aes, we have x = Description, but in your data set, the column name Description is mismatching.
please check your data set if you have a column " Description".
the code I pasted in the post works for me with no error.

It gives me this error when I copy paste your code with the same example data

Try to restart RStudio and delete all load objects. Im copy/paste and the code make for @melih_guven run well.

Remember activate tibble and tidyverse.

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

If you have a query related to it or one of the replies, start a new topic and refer back with a link.