Question: scatterplotmatrix subscript labels
gravatar for dp0b
3.7 years ago by
dp0b60 wrote:


I am using the car package in R to complete a scatterplot matrix with linear regression lines. I wish the column names on diagonal to be in subscript for some of the characters, is there a way I can incorporate expression into var labels?

scatterplotMatrix(inbred[1:4],smooth = FALSE,ylim=c(0,0.35), xlim=c(0,0.35), reg.line = lm,diagonal=c("none"),var.labels=colnames(inbred))

I have tried the following

scatterplotMatrix(inbred[1:4],smooth = FALSE,ylim=c(0,0.35), xlim=c(0,0.35), reg.line = lm,diagonal=c("none"),var.labels=colnames(expression(F[123]), expression(F[222]), expression(F[333]), expression(F[444])))

Thanks! :)

scatterplot car R • 1.5k views
ADD COMMENTlink modified 3.7 years ago by WouterDeCoster44k • written 3.7 years ago by dp0b60

I usually use ggplot so if you would like to use that you can use geom_text() function to label selected points.

ADD REPLYlink written 3.7 years ago by Sej Modha4.7k
gravatar for WouterDeCoster
3.7 years ago by
WouterDeCoster44k wrote:

I once had a lot of fun trying to get an exponent for R^2 in a ggplot geom_point()/geom_smooth() graph.
I can confirm this works for my specific case, but I'm not sure it will work for your needs:

rsquare = paste("R^2 == ", signif(cor$estimate, 3), sep="")
p <- ggplot(data=comb, aes_string(x=gene, y = paste("QS", gene, sep="_"))) +
    geom_point() +
    geom_smooth(method = "lm", se = FALSE) +
    annotate("text", x=max(comb[,gene])-1, y=min(comb[,paste("QS", gene, sep="_")])+0.3, label=rsquare, parse=TRUE, size=4, hjust=0) +

The magic is in the parse=TRUE part of annotate, converting the ^2 to a superscript 2.

EDIT: see that you are talking about "subscript" and not superscript, but possibly similar magic exists...

ADD COMMENTlink modified 3.7 years ago • written 3.7 years ago by WouterDeCoster44k
Please log in to add an answer.


Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1962 users visited in the last hour