1

I'm using R to plot my data, but am unable to install packages for the moment as my workplace has put up a lot of firewalls (currently trying to get IT to get them down). In the meantime, I was wondering if by using the plot() function I was able to plot my data in groups. I have three variables in my data: IDName, Value, and Setpoints. I wanted to aggregate my values for each setpoint thus I used the aggregate() function although this will aggregate all data for each setpoint, whereby I only want it to aggregate depending on the IDName. All forms of grouping seem to require a package, thus I was wondering if anyone knew any workarounds.

I've supplied the code below (note that the R script is within PowerBI, but for the purposes of my question only R expertise is needed). It would also be great if you know how to colour these points accordingly to each IDName.

# dataset <- data.frame(IDName, Value, Setpoints)
# dataset <- unique(dataset)

# Paste or type your script code here:
dat <- aggregate(Value ~ Setpoints, dataset, mean)

x <- dat$Value
y <- dat$Setpoints
z <- dataset$IDName
plot(x,y, main ="Turbidity Frequency Distribution",xlab="% Time < Turbidity level", ylab="Turbidity (NTU)")
lines(spline(x,y))

Ben Bolker
  • 211,554
  • 25
  • 370
  • 453
  • 2
    Please [make this question reproducible](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) by including example data in a plain text format - for example the output from `dput(dat)`. – neilfws Dec 24 '20 at 00:07
  • do you mean that you want a single value computed per combination of values of `Setpoints` and `IDName` ? – Ben Bolker Dec 24 '20 at 00:18
  • Seems to flesh out the data the way I want when I change the aggregate function to the following: dat <- aggregate(Value ~ Setpoints + IDName, dataset, mean) but I am still unsure how to colour the points by IDName and to get the lines(spline(x,y)) to do curves for each IDName rather than one averages line. Any ideas? Thanks – Ashling Charles Dec 24 '20 at 01:04
  • Unsure how to include example data as I'm running my script in powerbi where there is no output on the data side via dput(dataset) – Ashling Charles Dec 24 '20 at 01:06

0 Answers0