0
votes

I am trying to plot only the first 220 rows out of the 260 in my data frame from the first and third column.

This is a "slice" of the data frame. I am trying not to include the "Average", "Pre.Covid" and "Change" rows in the ggplot2 code.

structure(list(Date = c("01-2019", "01-2019", "01-2019", "01-2019", 
                    "01-2019", "Average", "Pre.Covid","Change"),
          Region = c("South East", "South West", "London", "East of England", 
          "East Midlands", "West Midlands", "Yorkshire and The Humber", 
          "North West"),
          Unemployment.rate = c("3.13", "2.916523", "4.210277", 
                     "3.194942", "4.682473", "5.070812", "5.231136", "3.607693")), 
      row.names = c(NA, -260L), 
      class = c("tbl_df", "tbl", "data.frame"))

I tried using the code below,

ggplot(df, aes(df[1:220,1], df[1:220,3], color = Region, group = Region)) +
            geom_line() +
            labs(x = "Date", y = "Unemployment rate (%)")

However, I get the following error message(s):

Don't know how to automatically pick scale for object of type tbl_df/tbl/data.frame. Defaulting to continuous.

Don't know how to automatically pick scale for object of type tbl_df/tbl/data.frame. Defaulting to continuous. (yes, twice)

Error in is.finite(x) : default method not implemented for type 'list'

Any idea how to work around that? Also, if anyone could please let me know how to change those numerical values into percentages with 2 decimals it would be great.

Thanks in advance for any help you can give!

1
please debug your dputAnilGoyal

1 Answers

1
votes

You can subset the dataframe before plotting without changing aes.

library(ggplot2)

ggplot(df[1:220, ], 
       aes(Date, Unemployment.rate, color = Region, group = Region)) +
  geom_line() +
  labs(x = "Date", y = "Unemployment rate (%)")