user2123601
user2123601

Reputation: 33

Can't label the dots in the dotplot

I have some multivariate data.

I want to draw a dotplot for this data, so I wrote the following code:.

a.data <- read.table("C:/Users/OGR001/Documents/veri2.csv", sep=",", header=TRUE)
library(lattice)
library(latticeExtra)


useOuterStrips(dotplot(reliability ~ factor(madde.sayisi) |  
                                    as.factor(orneklem)*as.factor(yontem),
                       groups=as.factor(formul),  
                       data=a.data, as.table=TRUE, 
                       horizontal=FALSE, 
                       jitter.x=TRUE))

The dotplot is ok, but I want to name the dots here.

How can I do this?

Upvotes: 2

Views: 1550

Answers (3)

Carl Witthoft
Carl Witthoft

Reputation: 21532

Edit: agstudy is correct that you can't use base graphics on a lattice window. Luckily theres a ltext command that does basically the same thing, so use ltext in the manner described below for base graphics' text .

Dunno what's easiest, but base::text certainly can do this. I'm going to assume you can use a factor or a column in your dataframe to select the sb , r, and f coordinate sets separately. so:

text(sb_x_coords, sb_y_coords, labels='sb',...)

where you can mod the fontsize, color, etc. Repeat for the other two categories.

Upvotes: 0

iantist
iantist

Reputation: 843

The car package allows easy labeling of dots in a scatterplot. We can use the iris dataset for illustration.

library(car)
scatterplot(Sepal.Length ~ Sepal.Width, data=iris,labels=iris$Species,id.method=T)

enter image description here

Upvotes: 1

agstudy
agstudy

Reputation: 121588

Without a reproducible example, it is really hard to help you! I answer just because it is a little bit challenging to custom panel of a lattice plot. basically you need to add this line :

            panel=function(x,y,...){
                 panel.dotplot(x,y,...)
                 labs <- dat[list(...)$subscripts,]$labs ## labs is your factor column!
                 panel.text(x,y,labs,adj=c(1.2,0.5))
               }))

For example, Here using barley from the lattice package.

dat <- barley
dat$labs <- sample(c('SB','R','F'),nrow(dat),rep=T)

useOuterStrips(dotplot(variety ~ yield | site*year, 
                       data = dat,
                       groups = year,
                       horizontal=TRUE, 
                       jitter.x=TRUE,  ylab=NULL,
               panel=function(x,y,...){
                 panel.dotplot(x,y,...)
                 labs <- dat[list(...)$subscripts,]$labs
                 panel.text(x,y,labs,adj=c(1.2,0.5))
               }))

enter image description here

Upvotes: 1

Related Questions