Create a ggplot graph with inferno instead of viridis color palette

107 views Asked by At

I have the dataset below

data<-structure(list(new_cat = c("animals", "art", "books", "business", 
"celebrity", "colleges", "fashion", "food", "games", "geography", 
"history", "language", "medicine", "military", "misc", "movies", 
"music", "mythology", "nature", "philosophy", "politics", "publications", 
"religion", "royalty", "science", "shakespeare", "sports", "technology", 
"theater", "tv", "usa", "work", "world"), jobzone = c(-0.0105999996885657, 
0.0111999996006489, 0.00490000005811453, 0.0187999997287989, 
-0.000300000014249235, 0.0274999998509884, 0.00579999992623925, 
-0.00689999992027879, -0.00600000005215406, 0.0175999999046326, 
0.0071000000461936, 0.0094999996945262, 0.0187999997287989, 0.0094999996945262, 
0.0082999998703599, -0.00989999994635582, -0.000600000028498471, 
-0.0197000000625849, -0.0130000002682209, 0.0131000000983477, 
0.0156999994069338, 0.0136000001803041, 0.0199999995529652, 0.0137999998405576, 
0.0175999999046326, 0.00529999984428287, 0.00680000009015203, 
-0.00039999998989515, -0.00659999996423721, -0.00680000009015203, 
0.0153000000864267, 0.0304000005125999, 0.00430000014603138), 
    gender = c(-0.0249000005424023, -0.0082999998703599, -0.0182000007480383, 
    -0.0500999987125397, -0.0205000005662441, -0.0712999999523163, 
    0.0619000010192394, 0.0103000001981854, -0.0723000019788742, 
    -0.0729999989271164, -0.0612999983131886, -0.0227000005543232, 
    -0.0148999998345971, -0.102300003170967, -0.0243999995291233, 
    -0.0296000000089407, -0.0288999993354082, -0.0187999997287989, 
    -0.0226000007241964, -0.0654999986290932, -0.0843999981880188, 
    -0.0606000013649464, -0.0348000004887581, -0.0149999996647239, 
    -0.0860999971628189, -0.00630000000819564, -0.130799993872643, 
    -0.0683000013232231, 0.00609999988228083, -0.0230999998748302, 
    -0.0538999997079372, -0.0693999975919724, -0.0511999987065792
    ), n = c(31041, 26811, 62019, 19413, 14448, 6873, 11994, 
    43848, 9183, 54375, 41538, 28536, 21783, 24579, 58488, 51846, 
    52392, 10995, 15987, 3276, 42849, 5931, 25839, 8367, 31488, 
    6699, 36417, 16908, 18468, 31074, 55770, 4524, 24174), score = c(0.216984122991562, 
    -0.0226046573370695, 1.9715895652771, -0.441630125045776, 
    -0.722849607467651, -1.15190041065216, -0.861845076084137, 
    0.942377388477325, -1.02106118202209, 1.53863060474396, 0.811538100242615, 
    0.0750999823212624, -0.307392448186874, -0.149025976657867, 
    1.77159249782562, 1.39538705348969, 1.42631268501282, -0.918428778648376, 
    -0.635680079460144, -1.35563588142395, 0.885793626308441, 
    -1.20525562763214, -0.0776591002941132, -1.06727969646454, 
    0.242302373051643, -1.16175580024719, 0.521482765674591, 
    -0.583514273166656, -0.495155304670334, 0.218853250145912, 
    1.61764395236969, -1.28494870662689, -0.171965315937996), 
    avgmoney = c(808.570007324219, 1032.0400390625, 965.710021972656, 
    802.549987792969, 778.710021972656, 885, 802.539978027344, 
    743.010009765625, 700.030029296875, 906.200012207031, 937.690002441406, 
    846.72998046875, 885.049987792969, 911.710021972656, 806.02001953125, 
    921.090026855469, 887.030029296875, 906.450012207031, 898.289978027344, 
    1108.31994628906, 909.799987792969, 895.460021972656, 871.179992675781, 
    928.330017089844, 964.830017089844, 934.710021972656, 764.440002441406, 
    830.330017089844, 1027.80004882812, 806.690002441406, 811.619995117188, 
    840.530029296875, 916.119995117188)), class = c("tbl_df", 
"tbl", "data.frame"), row.names = c(NA, -33L))

I'd like the size of the dots to represent the size of each category (variable n), and the color of the dots to be based on the value of each category (variable avgmoney).

I'd like to try this with both viridis and inferno color schemes, with the label "Average Money" in the graph. The x-axis is variable jobzone and the y-axis is variable gender.

I did it with viridis with but not with inferno

    # Load required libraries
library(ggplot2)
library(viridis)
library(colourvalues)
# Create the scatter plot
p <- ggplot(bourdieuclassgender, aes(x = jobzone, y = gender, size = n, color = avgmoney)) +
  geom_point() +
  scale_size_continuous(range = c(3, 12)) +
  scale_color_viridis(name = "Average Money") +
  labs(x = "Correlation: Job Zone and Contestant Responses",
       y = "Correlation: Female Contestant and Response") +
  theme_minimal() +
  theme(legend.position = "right")

# Print the plot
print(p)
0

There are 0 answers