ggplot2 error messages receives

Can someone help with plotting in R using tidyverse? I got some errors.

These are the error messages:
Don't know how to automatically pick scale for object of type <tbl_df/tbl/data.frame>. Defaulting to continuous.
Error in geom_bar():
! Problem while computing aesthetics.
:information_source: Error occurred in the 1st layer.
Caused by error in check_aesthetics():
! Aesthetics must be either length 1 or the same as the data (82964)
:heavy_multiplication_x: Fix the following mappings: y
Run rlang::last_trace() to see where the error occurred.

ggplot(data = df_clean)+

  • geom_bar(mapping = aes(x = state, y = price))

Error in geom_bar():
! Problem while computing stat.
:information_source: Error occurred in the 1st layer.
Caused by error in setup_params():
! stat_count() must only have an x or y aesthetic.

I think you have some confusion around your nanes for things, and also where they are located.

You start with df_clean, seems a good enough name, i can infer that its a data.frame. you calculate a column called avg_price and store that in a data.frame also called avg_price. Now you have the mental challenge to understand that there is not one thing alone that is called avg_price but 2, and you open up the door for your own idea to not match watch you in fact instructed the computer to do for you. Calling the frame that contains the avg_price field something like avg_price_df might help you with your mental model.

I looked the object_names where values are stored and you are right. I've made avg_price twice. I never looked of the data.frames I made before posting it here. Thank you for noticing it. I never looked at it. Let me try again and correct it.

I am just following how the format of ggplot in the R programming used in Coursera: Data Analytics. Yet, still confused how to use the ggplot. Can you give me an advice how will I learn it easily?

I learned from this book:

Thank you with that book you shared. I have read that book you mentioned after I finished my Coursera: Data Analytics course. I am reading this book now:

It is a 2nd Edition of the first one.

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.