0

I am working with the R programming language. Normally when I make plots, I am using the ggplot2 library and the aes() options can be used to label the x-axis and add a title. However this time, I the plots I am making are not ggplot2 objects, and therefore can not be labelled in the same way:

library(MASS)
library(plotly)

a = rnorm(100, 10, 10)

b = rnorm(100, 10, 5)

c = rnorm(100, 5, 10)

d = matrix(a, b, c)

parcoord(d[, c(3, 1, 2)], col = 1 + (0:149) %/% 50)

#error - this is also apparent because the ggplotly() command can not be used.
ggplotly(d)

Does anyone know how to add labels on the x-axis of this plot and some title? Can the ggplotly command be used here?

Thanks

nick
  • 1,090
  • 1
  • 11
  • 24
stats_noob
  • 5,401
  • 4
  • 27
  • 83

1 Answers1

1

You can use title(), e.g.

library(MASS)

a = rnorm(100, 10, 10)
b = rnorm(100, 10, 5)
c = rnorm(100, 5, 10)
d = matrix(a, b, c)

parcoord(d[, c(3, 1, 2)], col = 1 + (0:149) %/% 50)
title(main = "Plot", xlab = "Variable", ylab = "Values")
axis(side = 2, at = seq(0, 5, 0.1),
     tick = TRUE, las = 1)

example_2.png

jared_mamrot
  • 22,354
  • 4
  • 21
  • 46
  • thank you for your answer! is it possible to add a numerical scale on the y-axis? – stats_noob Jan 21 '21 at 22:26
  • for example, if this was a ggplot object: p1 = p + scale_y_continuous() – stats_noob Jan 21 '21 at 22:28
  • maybe something like this? axis(4, at=Values ,labels=round(z,digits=2), col.axis="blue", las=2, cex.axis=0.7, tck=-.01) #source: https://www.statmethods.net/advgraphs/axes.html – stats_noob Jan 21 '21 at 22:34
  • 1
    Updated example to include y-axis tick marks / values – jared_mamrot Jan 21 '21 at 22:43
  • Thanks again! Is it impossible to do this? A = parcoord(d[, c(3, 1, 2)], col = 1 + (0:149) %/% 50) Ggplotly(A) – stats_noob Jan 21 '21 at 22:48
  • Thank you for all your help today @Jared_mamrot. The last thing I was trying to do was see if if is possible to make this kind of plot with numeric and factor variables? I don't want to bother you too much, but perhaps if you have time you could take a look at this? https://stackoverflow.com/questions/65836522/r-non-numeric-arguments-to-binary-operators thanks again for everything – stats_noob Jan 21 '21 at 22:49