Skip to content

Instantly share code, notes, and snippets.

@memilanuk
Created May 15, 2017 00:12
Show Gist options
  • Save memilanuk/4563592111b2a80d6f452fddc14aba74 to your computer and use it in GitHub Desktop.
Save memilanuk/4563592111b2a80d6f452fddc14aba74 to your computer and use it in GitHub Desktop.
Contour Plot / Heat Map for Load Development
require(lattice)
require(spatial)
groups <- read.csv(file="Desktop/damoncali.csv",head=TRUE,sep=",")
groups$x <- groups$CBTO
groups$y <- groups$Charge
groups$z <- groups$ES.MOA
x.Margin <- 0.00
y.Margin <- 0.0
groups.ls <- surf.ls(3, groups$x, groups$y, groups$z)
groups.surface <- trmat(groups.ls, min(groups$x) - x.Margin, max(groups$x) + x.Margin, min(groups$y) - y.Margin, max(groups$y) + y.Margin, 500)
str(groups.surface)
colfunc <- colorRampPalette(c("green", "yellow", "orange", "red"))
image(groups.surface, col = colfunc(12)) #heat.colors(20))
contour(groups.surface, labcex = .75, add=T, nlevels = 20)
points(groups$x, groups$y)
title(
xlab="CBTO (in)",
ylab="Varget (gr)"
)
@damoncali
Copy link

damoncali commented May 15, 2017

With the csv input in the same directory you should be able to just run "Rscript loaddev.r", and it should spit out a pdf file of the plot. I'm not sure the file path is right.

@damoncali
Copy link

screen shot 2017-05-14 at 7 42 10 pm

This is how I run it (on my mac). If you run it again, it just overwrites the Rplots.pdf file (which is the one it generates). You need the script on and the csv file in the same directory and it should just work. Not sure what it's like on a non-mac.

@memilanuk
Copy link
Author

Yeah... the file locations aren't an issue; it looks like this bug for the Debian Linux flavors of R may be what is biting me in the butt... running Linux Mint 18 on a Dell Chromebook 13, using RStudio.

screenshot from 2017-05-14 18-17-18

@damoncali
Copy link

I'm using R 3.3.3 for what it's worth.

@memilanuk
Copy link
Author

Okay... that was a PITA. Tried downgrading the r-base package, hoping the others would follow suite... no go. Ended up uninstalling all of R, and re-installing it. Then updating the stuff pulled in as a part of r-base, which forced a recompile of the offending packages. Seems to be working now.
screenshot from 2017-05-14   @@18-56-21

@damoncali question on the code... any particular reason you took columns from the CSV file i.e. groups$CTBO and turned around and created new columns in the data frame i.e. groups$x instead of just x <- groups$CTBO?

I went thru and changed all the other references to groups$x and groups$y to just x and y, and the script / plot still seems to work just fine, and looks a bit cleaner as well.

require(lattice)
require(spatial)

groups <- read.csv(file="damoncali.csv",head=TRUE,sep=",")

x <- groups$CBTO
y <- groups$Charge
z <- groups$ES.MOA
x.Margin <- 0.00
y.Margin <- 0.0

groups.ls <- surf.ls(3, x, y, z)
groups.surface <- trmat(groups.ls, min(x) - x.Margin, max(x) + x.Margin, min(y) - y.Margin, max(y) + y.Margin, 501)

str(groups.surface)

colfunc <- colorRampPalette(c("green", "yellow", "orange", "red"))

image(groups.surface, col = colfunc(12)) #heat.colors(20))
contour(groups.surface, labcex = .75, add=T, nlevels = 20)
points(x, y)

title(
  xlab="CBTO (in)",
  ylab="Varget (gr)"
)







@damoncali
Copy link

damoncali commented May 15, 2017

The code is a little sloppy. I wasn't sure what I was going to do with it and never really thought anyone else would ever see it, honestly. So yeah, there are some weird spots. I basically stoped working on it the second it worked. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment