0

Goal: 1.Plot
Time vs demand Time vs OT_ratio Time vs approdH all on the same plot.

Details:

BOD

  Time demand OT_ratio  approxH
1    1    8.3 8.300000 3.060645
2    2   10.3 5.150000 2.695417
3    3   19.0 6.333333 4.256347
4    4   16.0 4.000000 7.997521
5    5   15.6 3.120000 2.599570
6    7   19.8 2.828571 5.678107
    BOD<_BOD %>% mutate(BOD,OT_ratio=demand/Time )
    BOD<-BOD %>% mutate(approxH=runif(n=6,min=2,max=9))
    ggplot(data=BOD,aes(x=approx,y=OT_ratio))+ 
    +     geom_line(alpha=1/2)
    Don't know how to automatically pick scale for object of type function. Defaulting to continuous.
    Error: Aesthetics must be valid data columns. Problematic aesthetic(s): x = approx. 
    Did you mistype the name of a data column or forget to add after_stat()?
    Run `rlang::last_error()` to see where the error occurred.

Any suggestions would be great. Thank you so much!
Toy L
  • 55
  • 6
  • 2
    It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input that can be used to test and verify possible solutions. Chances are your data is in an odd structure so showing the `dput()` will clear that up. – MrFlick Jul 15 '21 at 00:56
  • Shortest course is to copy the full error message and see many others have contended with this and look for an example much like yours that will help you present a [reproducible](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example), as from the error, there are many, and without your `dput`, you're in the best position to say which is most representative. – Chris Jul 15 '21 at 01:30
  • Okay, I will update the post with a reproducible example. – Toy L Jul 15 '21 at 01:38
  • Hopefully, the updated post is more clear. – Toy L Jul 15 '21 at 01:51

1 Answers1

0

You've got errors in your post. I'm not sure if that's actually what you have coded in R or if this is just a typo in your post. Mistakes happen, ya know?

When you use a function like runif() you should seed it, so that you can at least see if you're getting the right results. Without seed() it will change every time.

Either way:

# this won't work:
# BOD<_BOD %>% mutate(BOD,OT_ratio=demand/Time )

BOD <- BOD %>% mutate(OT_ratio = demand/Time)

# there was an underscore before BOD and you called the data two times

# here you named the field approxH, but called approx
# BOD<-BOD %>% mutate(approxH=runif(n=6,min=2,max=9))

# set seed for repeatability
set.seed(36)
BOD <- BOD %>% mutate(approx = runif(n = 6, min = 2, max = 9))

# you have a few +'s here that could be from copying the console, though

# ggplot(data=BOD,aes(x=approx,y=OT_ratio))+ 
# +     geom_line(alpha=1/2)

ggplot(data = BOD,
       aes(x = approx,
           y = OT_ratio)) +
  geom_line(alpha = 1/2)

Here's what I've got: enter image description here

Kat
  • 15,669
  • 3
  • 18
  • 51
  • Yes, They were typos. The "+" was from copying from the console, the approx should have been approxH,and the "_" was typing error. Thanks for the corrections. My origional question is how to add another plot over it? add another y-axsis and plot time on x-axis and demand on y-axis – Toy L Jul 15 '21 at 21:09
  • What is the significance of 36 in the set.seed? – Toy L Jul 15 '21 at 21:12
  • The number within `set.seed()` is random. It really doesn't matter what number you use; it's there as a control. That is so you can get a random set of numbers the first time but have that same set of numbers if you wanted to rerun the code. – Kat Aug 05 '21 at 05:30
  • Oh, I see. Thanks – Toy L Aug 07 '21 at 04:24