[R] how do I draw such a barplot?

Donatas G. dgvirtual at akl.lt
Fri Jul 20 14:59:18 CEST 2007


I did not have much success with ggplot2 and reshape libraries, so finally I 
managed to work out the graph in a rather complicated way. The only thing I 
cannot figure out is, how do I place the legend outside the barplot column 
area?

attach(tolerancija.data)
ateist = table(G09_01)
dvasin = table(G09_02)
gamtos = table(G09_03)
kr_klm = table(G09_04)
musulm = table(G09_05)
na_kri = table(G09_06)
pagoni = table(G09_07)
satani = table(G09_08)
rytų_k = table(G09_08)
satani = table(G09_09)
tradic = table(G09_10)
eilutes=cbind(ateist,dvasin,gamtos,krikšč,musulm,kr_klm,na_kri,pagoni,rytų_k,satani,tradic)
barplot(prop.table(eilutes,2),col=c("red3","red2","cyan","green2","green3"),legend.text=c("visiškai 
sutinku","nesutinku","abejoju","sutinku","visiškai sutinku"),main="My title")
dettach(tolerancija.data)

However, this is a lot of writing. How do I make into a function to be 
reusable? 


Donatas

On Jul 16, 2007, at 9:06 , Donatas G. wrote:

> Hi,
>
> I cannot figure out how to draw a certain plot: could someone help  
> me out?
>
> I have this data.frame from a survey
> my.data
>
> that looks like something like this:
>
>    col1  col2  col3  col4
> 1     5     5     4     5
> 2     3     5     3     1
> 3     2     3     4     5
> 4     3     1     1     2
> 5     5     5     4     5
> 6     4     2     5     5
> ....
>
>
> Each row represents a single questionnaire with someone giving his
> agreement/disagreement with a statement (each column is a  
> statement) that is
> coded from 1 to 5.
>
> I need to draw a barplot giving a visual representation showing  
> differences
> between the five columns: Each bar should represent a single  
> column, and
> should be divided into 5 sections, the thickness of each depending  
> on the
> number of respondents who choose that particular answer.
>
> How do I do that? All I have managed to do so far is to produce a  
> barplot of a
> single column, and that - only with bars side by side...


-- 
Donatas Glodenis
http://dg.lapas.info



More information about the R-help mailing list