-1

I currently have a plot of my data that looks like this:

plot of my data

However because of the negative spike in around 2017, the graph shows values above and below the x axis. How do I make it so the graph only shows values above the x axis?

This is the code I am currently using to produce my graph

plot(dandpw) addLegend(lty = 1)

mydata > head(dandpw) QLD1.Price NSW1.Price VIC1.Price SA1.Price TAS1.Price 2008-01-07 10:30:00 33.81019 36.52777 49.66935 216.45379 30.88968 2008-01-14 10:30:00 45.09321 37.55887 49.04155 248.33518 51.16057 2008-01-21 10:30:00 27.22551 29.57798 31.28935 31.56158 45.99226 2008-01-28 10:30:00 26.14283 27.32113 30.20470 31.90042 53.48170 2008-02-04 10:30:00 91.86961 36.77000 37.09027 37.57167 56.28464 2008-02-11 10:30:00 62.60607 28.83509 34.95866 35.18217 55.78961

dput(head(dandpw

halfer
  • 19,824
  • 17
  • 99
  • 186
user8261831
  • 464
  • 1
  • 4
  • 20
  • Can you include the output from `dput(head(dandpw))` instead? Easier for us to paste into R – morgan121 Dec 13 '18 at 05:58
  • > dput(head(dandpw)) structure(c(33.8101941747573, 45.0932142857143, 27.225505952381, 26.1428273809524, 91.8696130952381, 62.6060714285714, 36.5277669902913, 37.558869047619, 29.5779761904762, 27.321130952381, 36.77, 28.8350892857143, 49.6693527508091, 49.0415476190476, 31.2893452380952, 30.2047023809524, 37.0902678571429, 34.9586607142857, 216.453786407767, 248.335178571429, 31.5615773809524, 31.9004166666667, 37.5716666666667, 35.1821726190476, 30.8896763754045, 51.1605654761905, 45.9922619047619, 53.4816964285714, 56.2846428571429, 55.7896130952381), – user8261831 Dec 13 '18 at 06:03
  • 2
    Comments aren't the easiest way to read dput and it looks like some of your output is being chopped off. Could you edit your question to include the dput output? – Emily Kothe Dec 13 '18 at 06:05
  • Yep, also what does dput mean – user8261831 Dec 13 '18 at 06:06
  • Type “?dput()” in R & hit enter. – massisenergy Dec 13 '18 at 08:05

1 Answers1

1

You can do this in two ways. Since there is no usable dput (only the picture), I assume your data is in a data frame.

  1. You can remove negative numbers from your dataset
  2. You can put limits on the y-axis shown in the chart (using ggplot2)

Method 1 (not recommended as it alters your data):

#remove negatives and replace with NA. Can also replace with 0 if desired
dandpw[dandpw < 0] <- NA

Method 2:

#assume dandpw is data frame
library(tidyverse)
names(dandpw)[1] <- "date" #looks like your date column might not be named
#ggplot prefers long format
dandpw <- dandpw %>% gather(variables, values, -date)
ggplot(data = dandpw, aes(x = date, y = values, color = variables)) +
 geom_line() + 
 coord_cartesian(ylim = c(0, max(dandpw$values, na.rm = T) * 1.1 ))
hmhensen
  • 2,974
  • 3
  • 22
  • 43