0

I have data: and want to plot the correspondence analysis of that data.

md <- structure(list(Interpret_ALdc=c(11.522, 19.834, 8.122,
28.901, 20.778, 7.745, 9.634, 3.589, 8.311),
Compare_ALdc=c(10.005, 7.504, 16.008, 12.506, 12.506, 6.003,
8.004, 1.501, 1.501), Account_ALdc=c(10.503, 22.756, 9.502,
24.506, 15.754, 7.752, 6.252, 7.002, 8.252),
Interpret_MErd=c(21.536, 19.383, 1.436, 16.511, 22.254, 14.358,
27.997, 5.743, 7.897), Compare_MErd=c(18.282, 1.828, 13.711,
1.828, 6.399, 5.484, 5.484, 1.828, 2.742), Account_MErd=c(24.687,
13.167, 4.937, 9.217, 7.571, 18.433, 11.521, 16.458, 2.633)),
row.names=c("VBZ", "VM", "VVD", "VVI", "CST", "JJR", "VVZ",
"II21", "PPH1"), class="data.frame")

library(languageR)

md.ca <- corres.fnc(md)
plot(md.ca)

But some text on the right is missing on the plot. Instead of "Compare_MErd", just "Compare" presents on the plot. How to expand the plot area to present all text?

AkselA
  • 8,153
  • 2
  • 21
  • 34
Hoang Le
  • 308
  • 1
  • 3
  • 14
  • Try passing `xlim` and `ylim` arguments, e.g. `plot(md.ca, xlim = c(-0.7, 0.7))`. – Roman Luštrik Feb 24 '19 at 09:38
  • I did try and it did not help. – Hoang Le Feb 24 '19 at 09:41
  • Can you please make your [question reproducible](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example)? – Roman Luštrik Feb 24 '19 at 09:49
  • Could you please click to linked "data" word to copy the data sheet and import the data as tags_ms <- read.table("clipboard", header = T, dec = ",") if your laptop is set point for decimals. And then run the left code. Hope it works. – Hoang Le Feb 24 '19 at 10:54
  • I made your example reproducible. For future reference, reproducible implies, among other things, that copy-paste-run is possible on our end. – AkselA Feb 24 '19 at 11:20
  • 1
    To add to @AkselA's comment, your example should be self-contained and should not reply on external sources. Sorry for not making this clear beforehand. – Roman Luštrik Feb 24 '19 at 12:21
  • Thank you @AlselA for your editing. That's a great example and explaination for a reproducible question. – Hoang Le Feb 24 '19 at 13:02

1 Answers1

1

You can fit everything by setting stretch=2 or somesuch, but it will extend the window limits symmetrically.

plot(md.ca, stretch=2)

enter image description here

Modifying the code of plot.corres() to allow for xlim/ylim adjustment is pretty straight forward. F.ex:

plot.corres <- function (x, main = "", addcol = TRUE, extreme = 0, rcex = 1, 
    rcol = 1, rlabels = "", stretch, ccex = 1, ccol = 2, 
    clabels = "", xlim, ylim, ...) 
{
    if (!is(x, "corres")) 
        stop("argument should be a correspondence object")
    dat = x@data$origOut
    xlimit = range(dat$rproj[, 1])
    ylimit = range(dat$rproj[, 2])
    if (!missing(xlim)) {
        xlimit <- xlim
    }
    if (!missing(ylim)) {
        ylimit <- ylim
    }
    if (!missing(stretch)) {
        xlimit = xlimit * stretch
        ylimit = ylimit * stretch
    } 
    plot(dat$rproj[, 1], dat$rproj[, 2], type = "n", xlim = xlimit, 
        ylim = ylimit, xlab = paste("Factor 1  (", round(x@data$eigenrates[1]/10, 
            1), " %)", sep = ""), ylab = paste("Factor 2  (", 
            round(x@data$eigenrates[2]/10, 1), " %)", sep = ""), ...)
    lines(c(max(dat$rproj[, 1]), min(dat$rproj[, 1])), c(0, 0))
    lines(c(0, 0), c(max(dat$rpro[, 2]), min(dat$rproj[, 2])))
    if (!(main == "")) 
        mtext(main, 3, 1)
    if (length(rcol) == 1) 
        rcol = rep(1, nrow(dat$rproj))
    if (length(rlabels) == 1) 
        rlabels = rownames(x@data$input)
    text(dat$rproj[, 1], dat$rproj[, 2], rlabels, cex = rcex, 
        col = rcol)
    if (addcol) {
        if (length(clabels) == 1) 
            clabels = colnames(x@data$input)
        if (extreme > 0) {
            x = data.frame(dat$cproj[, 1:2])
            extremes = apply(x, 2, quantile, c(extreme, 1 - extreme))
            Accept = as.factor((x[, 2] < extremes[1, 2] | x[, 
                2] > extremes[2, 2]) | (x[, 1] < extremes[1, 
                1] | x[, 1] > extremes[2, 1]))
            text(x[Accept == TRUE, 1], x[Accept == TRUE, 2], 
                clabels[Accept == TRUE], font = 2, cex = ccex, 
                col = ccol)
        }
        else {
            text(dat$cproj[, 1], dat$cproj[, 2], clabels, font = 2, 
                cex = ccex, col = ccol)
        }
    }
}

plot(md.ca, xlim=c(-0.6, 1))

enter image description here

You could ask the author of the function if he could revise it.
His name and contact information is at ?corres.fnc

AkselA
  • 8,153
  • 2
  • 21
  • 34