I have a dataframe like df:
df <- structure(list(VarBinariaY = c("1", "1", "0", "1", "0", "1",
"1", "1", "1", "1"), VarContinuaX = c(0.42125112307258, 0.403089860687032,
0.501541076926515, 0.285735354525968, 0.838761311257258, 0.728340754751116,
0.547309613088146, 0.758638551225886, 0.664854867151007, 0.730170585680753
), VarContinuaY = c(0.62294910964556, 0.153794215992093, 0.173481315141544,
0.441902326885611, 0.556428883690387, 0.300496574025601, 0.778148024342954,
0.358530796831474, 0.163795455591753, 0.658571016974747)), row.names = c(NA,
10L), class = "data.frame")
and I want to plot a boxplot and a cloudplot having in the first Y-axis a character variable (1, 0), and in the second Y-axis a numeric variable between (0,1). I want both data points/boxplot to overlap with each other, so to be in the same scale. However, geom_point stays always below the scale of the first Y-axis. Moreover, I would like to have 2 Y-axis instead of a legend.
Here is my trial:
ggplot(df, aes(x = VarContinuaX)) +
geom_boxplot(aes(y = VarBinariaY ), outlier.shape = NA) +
coord_cartesian(xlim = c(-1, 1)) +
geom_point(aes(y = VarContinuaY, color = as.factor(VarBinariaY ))) +
scale_color_manual(values = c("blue", "red"),
labels = c("0", "1"),
guide = guide_legend(title = "Recommend")) +
labs(y = "First Axis", color = "Second Axis")[![enter image description here][1]][1]
Any clue?
Read more here: Source link