How do I plot the following in R?

plot, r

Solution

Here's one way using base graphics:

plot(c(1,3),range(mat1),type = "n",xaxt ="n")
points(1:3,mat1[,2])
points(1:3,mat1[,1],pch = "x")
axis(1,at = 1:3,labels = rownames(mat1))

Edited to include different plotting symbol

Problem

I'm new to plotting in R so I ask for your help. Say I have the following matrix. ``` mat1 <- matrix(seq(1:6), 3) dimnames(mat1)[[2]] <- c("x", "y") dimnames(mat1)[[1]] <- c("a", "b", "c") mat1 x y a 1 4 b 2 5 c 3 6 ``` I want to plot this, where the x-axis contains each rowname (a, b, c) and the y-axis is the value of each rowname (a = 1 and 4, b = 2 and 5, c = 3 and 6). Any help would be appreciated! ``` | o | o x | o x | x |_______ a b c ```

Original source