DS4PS / cpp-526-spr-2020

Course shell for CPP 526 Foundations of Data Science I for Spring 2020.
http://ds4ps.org/cpp-526-spr-2020/
3 stars 0 forks source link

Final Project - Plotting hours v harm #32

Open ecking opened 4 years ago

ecking commented 4 years ago

Hi there,

So I'm trying to plot on the x axis hours and the y axis number of total injuries + total fatalities. I've been trying out so many things and I keep getting errors. This last one says x and y lengths differ. Shouldn't points be x = hours and y = harmcount?

I rewatched the video from lab 3 on rendering plots and putting points down looked so easy. :/

Here is a piece of code:



harmcount <- sum(dat$Totalfatalities+dat$Totalinjuries)
hours <- dat$hour

renderPlot({

street.name <- input$Street
dat.name <- filter(dat, StreetName == street.name)

plot.new()

plot.window(xlim = c(0, 24), 
            ylim = c(0,45))

points(hours,harmcount,
       col = "gray85",
       pch = 16,
       cex = 0.75)`
ecking commented 4 years ago

So I got the plot to work with the selection of the street... for the most part. When I change the picklist value the plots change. But I'm not entirely sure how to figure out why/what the graph is actually populating. It should be the harmcount which is total injury plus total fatalities. Ideas on how to figure this out?

`dat12 <- input$Street dat.street <- filter(dat, StreetName == dat12)

plot.new()

plot.window(xlim = c(0, 24), ylim = c(0,100))

points(dat.street$hour, dat.street$harmcount, col="darkred",pch = 16, cex = 1 )`

image

lecy commented 4 years ago

Try this:


x <- 1:5
y1 <- rnorm(5)
y2 <- rnorm(5)

plot( x, y1 )

y3 <- y1 + y2
plot( x, y3 )

y4 <- sum( y1 + y2 )
plot( x, y4 )

y3
y4

Pay attention to how you are creating harmcount. Should the result be a vector? Or a single value?