Not sure why you are making this so complicated. In what way is the
following not meeting your expectations?
ggplot( data=matz
, aes( x = X1
, y = value
, col=X2
, lty=X2
, shape=X2
, size=mylwd
)
) +
geom_line() +
geom_point( size = 3 ) +
scale_linetype_manual( values = ltyvect ) +
scale_color_manual( values = colvect ) +
scale_size_continuous( range = c( 0.1, 2 ) ) +
theme( legend.title = element_blank() )
On Fri, 30 Oct 2015, Brian Smith wrote:
Hi,
I was trying to increase the size of certain lines in my plot (samples 'B'
and 'D' in example below). However, when I try to modify the line size, I
seem to screw up the linetypes. Also, is there a way to reflect the line
size in the legend?
Here is some sample code for illustration:
library(reshape)
matx <- matrix(sample(1:1000),4,5)
colnames(matx) <- LETTERS[1:5]
rownames(matx) <- 1:4
subset1 <- c('B','D')
ltyvect <- c("solid","longdash","longdash","solid","solid")
colvect <- c("red","black","orange","blue","lightblue")
lwdvect <- rep(1,ncol(matx))
## For subset of samples, increase line width size
fmakelwd <- function(set1,subset1,vals1,val2=2){
idx <- set1 %in% subset1
vals1[idx] <- val2
return(vals1)
}
maty <- melt(matx)
set1 <- maty$X2
vals1 <- rep(1,length(set1))
mylwd <- fmakelwd(set1,subset1,vals1,val2=1.5)
matz <- data.frame(maty,mylwd)
# code without trying to modify line size
p <- ggplot(data=matz,aes(x=X1, y = value,col=X2,lty=X2,shape=X2))
p <- p + geom_line(aes(group = X2)) + geom_point(aes(shape =
factor(X2)),size=3) +
scale_linetype_manual(values = ltyvect) +
scale_color_manual(values = colvect) +
theme(legend.title = element_blank())
p
# modifying line size
p <- ggplot(data=matz,aes(x=X1, y =
value,col=X2,lty=X2,shape=X2,size=mylwd))
p <- p + geom_line(aes(group = X2,size=mylwd)) + geom_point(aes(shape =
factor(X2)),size=3) +
scale_linetype_manual(values = ltyvect) +
scale_color_manual(values = colvect) +
scale_size(range=c(0.1, 2), guide=FALSE) +
theme(legend.title = element_blank())
p
#
thanks!!
[[alternative HTML version deleted]]
__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
---
Jeff NewmillerThe . . Go Live...
DCN:Basics: ##.#. ##.#. Live Go...
Live: OO#.. Dead: OO#.. Playing
Research Engineer (Solar/BatteriesO.O#. #.O#. with
/Software/Embedded Controllers) .OO#. .OO#. rocks...1k
__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.