Changing the names of labels and legend

Dear R-Studio Community,
Although I initially had lots of troubles realizing my likert plot, I now managed to do so. I have created a plot I'm happy with, such as the one attached. I already managed to change the names of "Community1" and "Community2".

Now I would also like to change the Responses 1-6 to "1 = Strongly agree", "2 = Slightly agree", "3=Agree", etc.
Instead of "econ_comm" I would like to have the original question, e.g. "This is the most important economic aspect for my community".

This is the code I want to work with...

#Laden der Daten aus Excel
g<-read.csv2("C:/Users/felix/OneDrive/Documents/R/SurveyData2.csv", sep=";", dec=",", header=TRUE)

#Both-Object erstellen
both<-g$Location

#Convert to factors
g <-  within(g, {
  econ_comm <- factor(econ_comm, levels=1:6)
  future_persp <- factor(future_persp, levels=1:6)
} )

comm_likert = likert(g[,2:3], grouping=g[,1])
plot(comm_likert)

Thank you very much for your help!!
Best, Felix

#Convert to factors
mylabels<-c("1 - love","2 - good",3:6)
g <-  within(g, {
  `pretty econ name` <- factor(econ_comm,labels=mylabels , ordered=TRUE)
  `nice future name` <- factor(future_persp, labels=mylabels,ordered=TRUE)
} )
#if 2:3 >> 4:5 as i added two new columns here
comm_likert = likert(g[,4:5],grouping = g[,1])
plot(comm_likert)

Dear nirgrahamuk,
That worked really fine for two variables. If I try to apply this to a range of factors (14 in total), I get this error:

> mylabels<-c("Completely agree","Agree","Slightly agree", "Slightly disagree", "Disagree", "Completely disagree" )
> g <-  within(g, {
+   `XXX` <- factor(agree_comm,labels=mylabels , ordered=TRUE)
+   `XXX` <- factor(future_persp, labels=mylabels,ordered=TRUE)
+   `XXX` <- factor(coexist_tradact,labels=mylabels , ordered=TRUE)
+   `XXX` <- factor(emigration_comm, labels=mylabels,ordered=TRUE)
+   `XXX` <- factor(fear_environ,labels=mylabels , ordered=TRUE)
+   `XXX` <- factor(gold_21cent, labels=mylabels,ordered=TRUE)
+   `XXX` <- factor(informed_deals,labels=mylabels , ordered=TRUE)
+   `XXX` <- factor(life_quality, labels=mylabels,ordered=TRUE)
+   `XXX` <- factor(proud_comm,labels=mylabels , ordered=TRUE)
+   `XXX` <- factor(support_govern, labels=mylabels,ordered=TRUE)
+   `XXX` <- factor(water_quant,labels=mylabels , ordered=TRUE)
+   `XXX` <- factor(work_project, labels=mylabels,ordered=TRUE)
+   `XXX` <- factor(workers_comm,labels=mylabels , ordered=TRUE)
+ } )
 Fehler in factor(proud_comm, labels = mylabels, ordered = TRUE) : 
  ungültige 'labels'; Länge 6 sollte 1 oder 5 sein 
> #if 2:3 >> 4:5 as i added two new columns here
> comm_likert = likert(g[,26:30],grouping = g[,1])
Fehler in `[.data.frame`(g, , 26:30) : undefined columns selected
> plot(comm_likert)

Do you have an idea why? I always get the same two scales as a result...

I would investigate what the unique() values of proud_comm are in the original dataset. I expect it will be different than the other variables

Also why is everything being renamed to XXX, that seems wrong?

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.