Skip to content

[R-es] problema con grafico lattice ....

4 messages · Carlos Ortega, eric

#
Hola,

Este es el código que produce el gráfico que envié...

#---------------------------
library(data.table)
library(lattice)

dat <- read.table("pba.csv", header=TRUE, dec=",", as.is=TRUE)
row.names(dat) <- NULL
dat <- as.data.table(dat)

#trellis.device(color=FALSE)
dat[con!=0, xyplot(mean ~ con
                   , groups=sol
                   , xlab=list("Solvent concentration (%v/v)", cex=1.2)
                   , ylab=list("Contact angle (º)", cex=1.2)
                   , ylim=c(70,140)
                   , scales=list(cex=1.1)
                   , cex=1.2
                   , panel=function(x,y){
                     panel.xyplot(x,y,cex=1.3, pch=c(1,2),
col=c('red','blue'))
                     panel.abline(h=c(103.141,101.779), lty=c(3,2))
                   }
)]

#-------------------

Con trellis.device(color = FALSE) simplemente abres una nueva ventana sin
color de fondo.
Para ver el motivo de la superposición de los puntos que te ocurre, tendría
que ver tu código.

Gracias,
Carlos

El 20 de enero de 2017, 18:39, eric <ericconchamunoz en gmail.com> escribió:

  
    
#
Hola,

Por si lo quieres con colores rellenando cada punto:

#----------------

library(data.table)
library(lattice)

dat <- read.table("pba.csv", header=TRUE, dec=",", as.is=TRUE)
row.names(dat) <- NULL
dat <- as.data.table(dat)

dat$mycol <- ifelse(dat$sol   =="ControlAE", "red", dat$sol)
dat$mycol <- ifelse(dat$mycol =="ControlAB", "blue", dat$mycol)
dat$mycol <- ifelse(dat$mycol =="Biodiesel", "tomato", dat$mycol)
dat$mycol <- ifelse(dat$mycol =="Decane", "black", dat$mycol)
dat$mypch <- ifelse(dat$sol   =="ControlAE", 21, dat$sol)
dat$mypch <- ifelse(dat$mypch =="ControlAB", 22, dat$mypch)
dat$mypch <- ifelse(dat$mypch =="Biodiesel", 23, dat$mypch)
dat$mypch <- ifelse(dat$mypch =="Decane", 24, dat$mypch)


dat <- as.data.frame(dat)
dat <- dat[dat$con!=0,]
xyplot(mean ~ con
       ,groups = sol
       ,data = dat
       ,xlab=list("Solvent concentration (%v/v)", cex=1.2)
       ,ylab=list("Contact angle (º)", cex=1.2)
       ,col = "black"
       ,cex = 2
       ,ylim=c(70,140)
       ,fill_col = dat$mycol
       ,el_pch = as.numeric(dat$mypch)
       ,panel = function(x, y, fill_col,el_pch,groups,...,subscripts) {
         fill <- fill_col[subscripts]
         pch <- el_pch[subscripts]
         panel.xyplot(x, y, pch = pch, fill = fill, ...)
         panel.abline(h=c(103.141,101.779), lty=c(3,2))
       }
      )

#----------------

[image: Imágenes integradas 1]

El 21 de enero de 2017, 0:24, Carlos Ortega <cof en qualityexcellence.es>
escribió:

  
    
#
Gracias Carlos, eres muy amable .. el codigo que produce mi grafico con los puntos superpuestos es el que envie en el primer mail que replico aqui, incluyendo la ventana grafica sin colores:


trellis.device(color=FALSE)
dat[con!=0, xyplot(mean ~ con
       , groups=sol
       , xlab=list("Solvent concentration (%v/v)", cex=1.2)
       , ylab=list("Contact angle (º)", cex=1.2)
       , ylim=c(70,140)
       , scales=list(cex=1.1)
       , cex=1.2
       , panel=function(x,y){
       panel.xyplot(x,y,cex=1.3, pch=c(1,2))
       panel.abline(h=c(103.141,101.779), lty=c(3,2))
       }
       )]


El grafico es para un articulo, asi es que debe ser sin colores.

Gracias por tu tiempo,

Saludos,

Eric.
On 01/20/2017 09:24 PM, Carlos Ortega wrote:

  
    
#
Hola,

Con este código, más sencillo, tienes diferentes símbolos y colores para
los dos tipos de "sol"...

#----------------------------------

dat <- as.data.frame(dat)
dat <- dat[dat$con!=0,]
xyplot(mean ~ con
       ,groups = sol
       ,data = dat
       ,xlab=list("Solvent concentration (%v/v)", cex=1.2)
       ,ylab=list("Contact angle (º)", cex=1.2)
       ,col = "black"
       ,cex = 2
       ,ylim=c(70,140)
       ,panel = function(x, y ) {
         panel.xyplot(x, y, pch = c(1,2), col = c('red', 'blue'))
         panel.abline(h=c(103.141,101.779), lty=c(3,2))
       }
      )

#----------------------------------

[image: Imágenes integradas 1]

Gracias,
Carlos.

El 21 de enero de 2017, 17:31, eric <ericconchamunoz en gmail.com> escribió: