I have 4 variables I would like to visually display a scatter plot of and use a colour code for the points greater than 0. Here's a snapshot of the data:
If your observations and variables are lined up correctly in this table, then how would you go about color coding observations where 2 or more variables are>0?
Are you just trying to have a binary color palette: one color for zeros, and one for non-zeros? Do variables colors matter (i.e. does solar_mtoe have to colored differently from solar_twh etc)?
While I'm not sure exactly what you want, my guess is that you could first gather all variables into 1 column, and have another column to indicate what variable that is, then create a binary color column, and then plot it, plotting the value onto color, and variable onto, let's say, shape.
You'd also want to use geom_jitter() since your x is Country and your y is Year, but you have 4 observations for each country-year pair, and thus will have 4 overlapping data points.
The following are variables: Country |Year|solar_mtoe|solar_twh|wind_mtoe|wind_twh|
The data listed below are the observations.
I was thinking to use a multi-color palette, one color for zeros, a second colour for both solar_mtoe and solar_twh and a third colour for wind_mtoe and wind_twh.
From what your desires are (and the final outcome's use totally escapes me, but I'll trust your judgment), I'd feature engineer another column and map it to color.
In the future, please try creating a minimally reproducible example via (e.g. via reprex package): you may have better luck getting more help from more users.
You're basically asking us to do your homework for you, so the least you can do is to make it easier for us to help you by creating a well formatted reprex.
it's also worth noting that the forum does have a homework policy: FAQ: Homework Policy
In short, homework inspired questions are OK, but try to parse your question down to the bit you're hung on and make a reprex of just that bit. Also make sure you format your posts so they are readable. You'll find that helpers are more forthcoming if you don't make them jump through a lot of hoops to see what you're doing (thus the reprex).
Thanks, I have installed reprex and followed the video. However, it doesn't work. It seems that the copy function is not copying to the clipboard to create the markdown. The is a reprex of the error:
No user-supplied code found … so we’ve made some up. You’re welcome!
If you run into problems with access to your clipboard, you can specify an infile and outfile for the reprex, and then copy and paste the contents into the forum.
Version: 1.0
#> Error in eval(expr, envir, enclos): object 'Version' not found
RestoreWorkspace: Default
#> Error in eval(expr, envir, enclos): object 'RestoreWorkspace' not found
SaveWorkspace: Default
#> Error in eval(expr, envir, enclos): object 'SaveWorkspace' not found
AlwaysSaveHistory: Default
#> Error in eval(expr, envir, enclos): object 'AlwaysSaveHistory' not found
EnableCodeIndexing: Yes
#> Error in eval(expr, envir, enclos): object 'EnableCodeIndexing' not found
UseSpacesForTab: Yes
#> Error in eval(expr, envir, enclos): object 'UseSpacesForTab' not found
NumSpacesForTab: 2
#> Error in eval(expr, envir, enclos): object 'NumSpacesForTab' not found
Encoding: UTF-8
#> Error in eval(expr, envir, enclos): object 'UTF' not found
RnwWeave: Sweave
#> Error in eval(expr, envir, enclos): object 'RnwWeave' not found
LaTeX: pdfLaTeX
#> Error in eval(expr, envir, enclos): object 'LaTeX' not found
# Use ggplot2 to visualize Solar and Wind
BP_Stats_Data <- BP_Stats_Data %>% mutate(Solar = solar_mtoe + solar_twh)
#> Error in BP_Stats_Data %>% mutate(Solar = solar_mtoe + solar_twh): could not find function "%>%"
You're getting this error because reprex needs to contain everything you need to reproduce the script, including the libraries. Without library(tidyverse) (or dplyr, and ggplot2, it doesn't matter), R doesn't "have" the %>% operator. The same goes for your data. Please see the aforementioned guides, which should help you with this.