Different stack barplots - same color legends
Say your dataframe is named prb.df:
oldnames<-names(prb.df)
ncol<-ncols(prb.df)
names(prb.df)<-paste0("Q",1:ncol)
barplot(...,names.arg=oldnames,...)
Jim
On Fri, Nov 2, 2018 at 1:56 AM P. Roberto Bakker
<robertobakker at gmail.com> wrote:
Yes, that is an good idea, only then I loose the original column lables which I need in my barplot. Isn't it? Op do 1 nov. 2018 om 11:03 schreef Jim Lemon <drjimlemon at gmail.com>:
I would use the "names" or "colnames" functions to change them to Q1, Q2, ... as I did. Jim On Thu, Nov 1, 2018 at 9:01 PM P. Roberto Bakker <robertobakker at gmail.com> wrote:
Hi Jim, Thank you for your quick reply. It is a great procedure. The response options in my data.frame are (fortunately) similar in all columns. It would be nice if I could use your procedure in all columns at once instead of each column. My data.frame contains 48 columns, each with long column names. This means that I need to put each (long) column name after "$: dataname$"very long name". So, is ther a way to do this procedure for all columns? Roberto Op do 1 nov. 2018 om 10:50 schreef Jim Lemon <drjimlemon at gmail.com>:
Hi Roberto,
What I suggested is a brute force method of translating response
options into ordinal numbers. Fortunately for me, the Barratt
Impulsivity Scale has relatively short and constant response options.
As I programmed the test myself, I already had the questions in plain
text, so I simply added the "as.numeric(factor(" and "levels=..."
commands to the forward and reversed response options to create the
whole transformation code. With a bit of cut-and-paste work, it didn't
take that long. Because the BIS-11 is used quite a bit where I am
working. it was worth the trouble.
Jim
On Thu, Nov 1, 2018 at 8:38 PM P. Roberto Bakker
<robertobakker at gmail.com> wrote:
Hi Jim, Thank you. An additional question: as I have many columns to change in numeric, and the columns are long sentences, what is an efficient way to do this? I checked in StackOverflow but could not find the right answer Best Roberto Op do 1 nov. 2018 om 00:25 schreef Jim Lemon <drjimlemon at gmail.com>:
Hi Roberto,
Here is a snippet of code that translates the text responses of the
BIS-11 into numeric values. Note the reversal of the order in the
second item:
BIS$Q1<-as.numeric(factor(BIS$Q1,
levels=c("Almost","Often","Occasionally","Rarely/Never")))
BIS$Q2<-as.numeric(factor(BIS$Q2,
levels=c("Rarely/Never","Occasionally","Often","Almost")))
...
Jim
On Thu, Nov 1, 2018 at 8:57 AM P. Roberto Bakker
<robertobakker at gmail.com> wrote:
Hi Rich, Thank you for your answer. The sentences are strings (likert scale: 'the situation is highly applicable to me' etc - in Dutch), or column labels; it may be confusing as it is in Dutch. Below I show you part of the dataframe with my annotation added (string/column lable) to give you an idea. I need to change the likert strings into numeric (1:5). And this is a challenge somehow. With dplyr, plyr it did not work. After I have the numeric version then I can stack them as suggested by David.