Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to transform my scatterplot into the correct one?

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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)

>Solution :

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading