Venus (female) and Mars (male) symbols in R plot – using Unicode

[This article was first published on gacatag, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

When analyzing a data constructed of individuals (or samples from individuals) of both male and female of a species (e.g. humans), often it is a good idea to compare the distribution of the various studied parameters for the males to those for the females. As for instance in RNAseq analysis, it is the measured expression of many genes may differ significantly between the studied males and females. In other words the gender may exhibit ‘batch effect’ in the gene expression data. Here is one way to use the neat Venus and Mars signs in an R-plot to label the data related to the females and males. Note that the male and the female signs were just randomly assigned here so no gender batch effect is noticeable in this figure.

#Generate normally distributed random variables
# and organize them in a 50*2 matrix
randM<-matrix(rnorm(100, 500, 50), ncol = 2)

#Output plot into png
png(“MaleFemale.png”, res=350, width=2000, height=2000)

#Randomly generate 50 MALE or FEMALE signs
gender<- sample(c("M","F"), 50, replace=T)

#Define suitable pch vector based on Unicodes of
#Venus (Female) and Mars (Mars)
pchVec<-rep(-0x2642L, nrow(randM))
pchVec[gender==”F”]<- -0x2640L

# Rndomly assign colors to define 3 subgroups within
#the 50 individuals
colors<- rainbow(3)
colVec<-sample(colors, 50, replace=T)

plot(randM, pch=pchVec, cex=2, col=colVec, xlab=”X”, ylab=”Y”)
legend(“topleft”, legend=c(“group1″,”group2″,”group3”),
       fill =colors)

To leave a comment for the author, please follow the link and comment on their blog: gacatag. offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)