2

I'm new to r and I want to recreate this scatterplot: enter image description here But I don't know how to get there. This is the code I have at this moment:

ggplot(satDf, aes(x=`Satisfaction Coefficient`, y=`Dissatisfaction Coefficient`)) + geom_point() + expand_limits(x=c(0.00, 1.00), y=c(0.00, -1.00))

which results in the following: enter image description here

satDf

enter image description here

CSV version of dataframe:

"","Attribute","Satisfaction Coefficient","Dissatisfaction Coefficient"
"1","Create an enjoyable interaction","0.47","-0.43"
"2","Create an enjoyable interaction","0.38","-0.24"
"3","Create an enjoyable interaction","0.29","-0.17"
"4","Create an enjoyable interaction","0.49","-0.49"
"5","Create an enjoyable interaction","0.48","-0.36"
"6","Create an enjoyable interaction","0.36","-0.26"
"7","Create an enjoyable interaction","0.37","-0.4"
"8","Create an enjoyable interaction","0.32","-0.29"
"9","Create an enjoyable interaction","0.25","-0.16"
"10","Create an enjoyable interaction","0.61","-0.57"
"11","Create an enjoyable interaction","0.49","-0.49"
"12","Create an enjoyable interaction","0.08","-0.18"

or

structure(list(Attribute = c("Create an enjoyable interaction", 
"Create an enjoyable interaction", "Create an enjoyable interaction", 
"Create an enjoyable interaction", "Create an enjoyable interaction", 
"Create an enjoyable interaction"), `Satisfaction Coefficient` = c("0.47", 
"0.38", "0.29", "0.49", "0.48", "0.36"), `Dissatisfaction Coefficient` = c("-0.43", 
"-0.24", "-0.17", "-0.49", "-0.36", "-0.26")), row.names = c(NA, 
6L), class = "data.frame")
if(!require('ggplot2')) {
  install.packages('ggplot2')
  library('ggplot2')
}
satDf <- read.csv("")
ggplot(satDf, aes(x=`Satisfaction Coefficient`, y=`Dissatisfaction Coefficient`)) + geom_point(col="blue") + expand_limits(x=c(0.00, 1.00), y=c(0.00, -1.00)) + geom_text(label=rownames(satDf), nudge_x = -0.25, nudge_y = -0.25)
Mout Pessemier
  • 1,665
  • 3
  • 19
  • 33
  • 1
    It would be easier to help you if you provide [a minimal reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) including a snippet of your data or some fake data. Please do not post an image of code/data/errors [for these reasons](https://meta.stackoverflow.com/questions/285551/why-not-upload-images-of-code-errors-when-asking-a-question/285557#285557). Please just include the code, console output, or data (e.g., dput(head(x)) or data.frame(...)) directly. – stefan Apr 12 '22 at 19:16
  • This said: From the image of you plot I would guess that your columns are characters instead of numerics. Hence, check your data using e.g. `str(satDf)`. – stefan Apr 12 '22 at 19:18

1 Answers1

4

Are you looking for something like this?

satDf$`Satisfaction Coefficient` <- as.numeric(satDf$`Satisfaction Coefficient`)
satDf$`Dissatisfaction Coefficient` <- as.numeric(satDf$`Dissatisfaction Coefficient`)

ggplot(satDf, aes(x=`Satisfaction Coefficient`, 
                  y=-`Dissatisfaction Coefficient`)) + 
  geom_label(x = 0.0, y = 0.55, label = 'Must - be', hjust = 0) +
  geom_label(x = 0.0, y = 0.45, label = 'Indifferent', hjust = 0) +
  geom_label(x = 1, y = 0.55, label = 'Performance', hjust = 1) +
  geom_label(x = 1, y = 0.45, label = 'Attractive', hjust = 1) +
  geom_point(col = 'deepskyblue3', size = 3) + 
  geom_text(aes(label = seq(nrow(satDf))), size = 3, nudge_x = -0.015,
            nudge_y = -0.02, check_overlap = TRUE) +
  geom_text(aes(label = 11), size = 3, nudge_x = -0.015,
                nudge_y = 0.02, data = satDf[11,]) +
  theme_light() +
  theme(panel.grid = element_blank()) +
  geom_hline(yintercept = 0.5) +
  geom_vline(xintercept = 0.5) +
  scale_y_continuous(labels = function(x) paste0('-', x),
                     limits = c(0, 1)) +
  xlim(c(0, 1))

enter image description here

Allan Cameron
  • 147,086
  • 7
  • 49
  • 87
  • Only difference, on the Y-axis, it are actually negative values. Can this be added as well or not? If not, I'll leave it be – Mout Pessemier Apr 12 '22 at 19:40
  • Amazing! Sorry to bother you once again, but I noticed that 11 is not present. 4 and 11 have the exact same score. Is there a way to show both overlapping values? – Mout Pessemier Apr 12 '22 at 19:45