0

I have been doing a graph and the x and y axis are very ugly. The numbers of each overall, and I was wondering how I could fix this so that maybe instead of every single x and y value available it would only show every couple so that it would look nice.

Picture of My Plot

This is my code:

billboard.data<- read.csv("https://raw.githubusercontent.com/hadley/tidy-data/master/data/billboard.csv") %>% 
  select(date.entered, date.peaked) %>% 
  filter(date.entered<"2000-10-01")

ggplot(data=billboard.data, aes(x=date.entered, y=date.peaked, group=1)) +
  geom_line()+
  geom_point()+
    labs (title = "The Time Between A Song Entering and Peaking",
        subtitle = "Is there A High Chance A Song Can Peak Higher After Debuting?",
        x = "Date Entered",
        y = "Date Peaked")+

Sorry I also don't know how to put that into the code format, but I hope everything makes sense and I am really looking for a simple answer. Asked prof for help and he said that it should be easy to figure out online and I am struggling.

r2evans
  • 141,215
  • 6
  • 77
  • 149
  • 2
    The simple answer is your x and y values are character string objects and not numeric values. Search here on stack overflow for how to convert. – Dave2e Mar 19 '21 at 00:40
  • 2
    Keep searching on SO, it's here in many questions: your values are not number-like, they are strings or factors. Read in your data and format as `Date`-class objects, and you'll have a lot more meaningful plot. And then you can use `scale_x_date (and `_y_`) to control the look of the axis, including ticks and labels. – r2evans Mar 19 '21 at 00:40
  • 1
    FYI, your `filter(date.entered<"2000-10-01")` *happens to work* because the string is formatted with most-significant-first. R is doing string-comparisons there, where `"1999" < "2000"`, and counter-intuitively `"210" > "2000"` (try it). In similar situations (with not-`Date` dates), I've seen `date.entered < "05/13/2020"` which is first comparing the months, then the days ... and only then if the months and days are the same does the year come into consideration. – r2evans Mar 19 '21 at 00:50
  • 1
    Bottom line, after `select(.)`, use `%>% mutate(across(c(date.entered, date.peaked), as.Date)) %>% filter(date.entered < as.Date("2000-10-01"))` and your plot will be much more usable and malleable. – r2evans Mar 19 '21 at 00:54
  • 2
    (And don't be discouraged by an early-close on the question. It's a common one, and the StackExchange community prefers to keep previous answers as the main reference so that they can be more-easily found. You included most of what makes a good question: sample code, reusable data, plot achieved, and clear communication of why it did not seem right. The one thing perhaps a little lacking, earning a downvote, was that there are many questions on SO about [tag:ggplot2] and axis control like this, so somebody thought you should have done more research. It's a good first question, stick around!) – r2evans Mar 19 '21 at 00:58

0 Answers0