Open kyarosiuk1 opened 2 years ago
renderPlot()
function whatever code is necessary to recreate the graphic, including the base/foundational code and the new, dynamic code which you've added.Thank you, your answers are helpful, but I am still struggling...any hints or help on how I should think on making the line specific to each region only? I tried to modify per below, but it does not work... geom_line(data = region_avgs, size = 1, aes(x = Year, y = Average, group = input$Region)
Also, I am having issue with the legend... I tried both codes below, but my legend is still not showing on the graph
legend() I tried to use legend function
or
scale_color_manual(name="legend", breaks=c('Region', 'Global Average'), values=c('Region'='yellow', 'Global Average'='blue')
@kyarosiuk1 sure thing! So what you need to do is "add on" another ggplot2 element.
Say your plot is in an object called p
. You can add a new graphical layer with the following approach:
p + my_new_layer
In our case:
p + geom_line()
Now, you can actually change the data source for this "geometry layer":
p + geom_line(data = region_avgs, aes(x = Year, y = Average), color = "red", size = 3)
I don't recall the specific code or variable names, but it would look like this.
Now - how do we make it so that line ONLY displays for the selected region? Well, simply filter it using the shiny input id:
region_subset <- region_avgs[region_avgs$Region == input$my_region, ]
Now repeat with your new geometry layer:
p + geom_line(data = region_subset , aes(x = Year, y = Average), color = "red", size = 3)
This should get you over the finish line!
Hello, in Lab 4 new version of Lab4, are we making dynamic the line that shows the average for each Region? There are so many lines in the code you provided that makes it confusing...
Can you please confirm that the below code (the line) is the one that needs to be dynamic? geom_line(data = region_avgs, size = 1, aes(x = Year, y = Average, group = Region), alpha = 0.4, color = "grey20")
Can you please clarify what should go into renderPlot ()? Do we include only the dynamic portion of the chart or do we include all the lines of the plot: including year_avg lines/points, etc.?
Can you please help me understand the below? I am struggling to understand why we would show the exact same line on the chart in white color and then again in blue? geom_line(data = year_avg, size = 1.5, aes(x = Year, y = Average), color = "white") +
Are we supposed to add a legend in this assignment? the assignment does not ask for it but I see one on the example we are replicating...
thank you so much for your help!