An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20090424/08d84b7d/attachment-0001.pl>
Text Contrast in a Plot
5 messages · Rodrigo Aluizio, Mark Difford, Greg Snow +1 more
Hi Rodrigo,
I would appreciate any suggestion on how can I make a text I?ve inserted in a plot show some contrast?
There are quite a few approaches, but why not try legend? Best, Mark.
Rodrigo Aluizio wrote:
Hi List,
I would appreciate any suggestion on how can I make a text I?ve inserted
in
a plot show some contrast? With this I mean that I have a white text on a
plot and I would like to make a tiny border around it in black, so even
being small sized and the entire graphic being small in the text page I?ll
insert it. It will be visible.
Well I tried inserting a box() function inside the text() function, R
accepts the command but there is no effect. I even tried to plot a greater
black text and then a smaller white one at the same place, but it doesn?t
look good.
Any ideas!
Bellow is my plot code without the above mentioned attempts. I?d like to
add
this effect at the second text() command.
png('BaseMap.png',width=5.2,height=3.6,pointsize=5,units='in',bg=NA,restoreC
onsole=T,res=1200)
par(mar=c(5,0,0,0))
map('worldHires','brazil',ylim=c(-5.15,-4.55),xlim=c(-37,-36.1),type='n')
rect(-37.1,-5.25,-36,-4.9,density=NULL,angle=45,col='#dbf4ff',border=F)
plot(Batimetria,ylab='',xlab='',border=F,col=Cor$Cor,add=T)
plot(Municipios,ylab='',xlab='',col=rgb(245,232,140,max=255,alpha=255),add=T
,lwd=0.2)
axis(1,xaxp=c(-37,-36.1,5),cex.axis=1.5)
axis(2,yaxp=c(-5.15,-4.55,5),cex.axis=1.5)
text(Prof$Long,Prof$Lat,rownames(Prof),col='black',cex=0.9,srt=-24,font=2)
text(c(-36.96,-36.96,-36.865,-36.54,-36.37,-36.2),c(-4.96,-5.05,-5.11,-5.14,
-5.14,-5.14),c('Areia
Branca','Serra
do Mel','Porto do
Mangue','Macau','Guamar?','Galinhos'),col='Black',cex=1.3,font=2)
rect(-36.20,-4.56,-36.155,-4.565,density=NULL,angle=45,col='black',border='b
lack',lwd=0.1)
rect(-36.155,-4.56,-36.111,-4.565,density=NULL,angle=45,col='white',border='
black',lwd=0.1)
text(c(-36.20,-36.155,-36.111,-36.215),c(-4.573,-4.573,-4.573,-4.562),c('0',
'5','10','km'),col='white',cex=1)
Norte(-36.155,-4.60,0.02)
box(which='plot',lty='solid')
dev.off()
Thanks in advance!
-------------------------------------------------------------
MSc. <mailto:r.aluizio at gmail.com> Rodrigo Aluizio
Centro de Estudos do Mar/UFPR
Laborat?rio de Micropaleontologia
Avenida Beira Mar s/n - CEP 83255-000
Pontal do Paran? - PR ? Brasil
[[alternative HTML version deleted]]
______________________________________________ R-help at r-project.org mailing list 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.
View this message in context: http://www.nabble.com/Text-Contrast-in-a-Plot-tp23217307p23221789.html Sent from the R help mailing list archive at Nabble.com.
Try this function as one approach:
shadowtext <- function(x, y=NULL, labels, col='white', bg='black',
theta= seq(pi/4, 2*pi, length.out=8), r=0.1, ... ) {
xy <- xy.coords(x,y)
xo <- r*strwidth('A')
yo <- r*strheight('A')
for (i in theta) {
text( xy$x + cos(i)*xo, xy$y + sin(i)*yo, labels, col=bg, ... )
}
text(xy$x, xy$y, labels, col=col, ... )
}
And here is an example of use:
plot(1:10, 1:10, bg='aliceblue')
rect(3,3,5,8, col='navy')
text(5,6, 'Test 1', col='lightsteelblue')
shadowtext(5,4, 'Test 2', col='lightsteelblue')
Hope this helps,
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.snow at imail.org
801.408.8111
> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of Rodrigo Aluizio
> Sent: Friday, April 24, 2009 8:12 AM
> To: R Help
> Subject: [R] Text Contrast in a Plot
>
> Hi List,
>
> I would appreciate any suggestion on how can I make a text I've
> inserted in a plot show some contrast? With this I mean that I have a
> white text on a plot and I would like to make a tiny border around it
> in black, so even being small sized and the entire graphic being small
> in the text page I'll insert it. It will be visible.
>
>
>
> Well I tried inserting a box() function inside the text() function, R
> accepts the command but there is no effect. I even tried to plot a
> greater black text and then a smaller white one at the same place, but
> it doesn't look good.
>
>
>
> Any ideas!
>
>
>
> Bellow is my plot code without the above mentioned attempts. I'd like
> to add this effect at the second text() command.
>
>
>
> png('BaseMap.png',width=5.2,height=3.6,pointsize=5,units='in',bg=NA,res
> toreC
> onsole=T,res=1200)
>
> par(mar=c(5,0,0,0))
>
> map('worldHires','brazil',ylim=c(-5.15,-4.55),xlim=c(-37,-
> 36.1),type='n')
>
> rect(-37.1,-5.25,-36,-4.9,density=NULL,angle=45,col='#dbf4ff',border=F)
>
> plot(Batimetria,ylab='',xlab='',border=F,col=Cor$Cor,add=T)
>
> plot(Municipios,ylab='',xlab='',col=rgb(245,232,140,max=255,alpha=255),
> add=T
> ,lwd=0.2)
>
> axis(1,xaxp=c(-37,-36.1,5),cex.axis=1.5)
>
> axis(2,yaxp=c(-5.15,-4.55,5),cex.axis=1.5)
>
> text(Prof$Long,Prof$Lat,rownames(Prof),col='black',cex=0.9,srt=-
> 24,font=2)
>
> text(c(-36.96,-36.96,-36.865,-36.54,-36.37,-36.2),c(-4.96,-5.05,-5.11,-
> 5.14,
> -5.14,-5.14),c('Areia
>
> Branca','Serra
>
> do Mel','Porto do
> Mangue','Macau','Guamar?','Galinhos'),col='Black',cex=1.3,font=2)
>
> rect(-36.20,-4.56,-36.155,-
> 4.565,density=NULL,angle=45,col='black',border='b
> lack',lwd=0.1)
>
> rect(-36.155,-4.56,-36.111,-
> 4.565,density=NULL,angle=45,col='white',border='
> black',lwd=0.1)
>
> text(c(-36.20,-36.155,-36.111,-36.215),c(-4.573,-4.573,-4.573,-
> 4.562),c('0',
> '5','10','km'),col='white',cex=1)
>
> Norte(-36.155,-4.60,0.02)
>
> box(which='plot',lty='solid')
>
> dev.off()
>
>
>
> Thanks in advance!
>
>
>
> -------------------------------------------------------------
>
> MSc. <mailto:r.aluizio at gmail.com> Rodrigo Aluizio
>
> Centro de Estudos do Mar/UFPR
> Laborat?rio de Micropaleontologia
> Avenida Beira Mar s/n - CEP 83255-000
> Pontal do Paran? - PR - Brasil
>
>
> [[alternative HTML version deleted]]
Thanks very much Greg and Mark for your attention.
The function that Greg created did the trick perfectly.
Once more thank you, I'll never be able to figure it out by myself, at least
not in time.
I'm still unable to write my own functions, but I'm working on it.
Rodrigo.
-----Mensagem original-----
De: Greg Snow [mailto:Greg.Snow at imail.org]
Enviada em: sexta-feira, 24 de abril de 2009 18:23
Para: Rodrigo Aluizio; R Help
Assunto: RE: [R] Text Contrast in a Plot
Try this function as one approach:
shadowtext <- function(x, y=NULL, labels, col='white', bg='black',
theta= seq(pi/4, 2*pi, length.out=8), r=0.1, ... ) {
xy <- xy.coords(x,y)
xo <- r*strwidth('A')
yo <- r*strheight('A')
for (i in theta) {
text( xy$x + cos(i)*xo, xy$y + sin(i)*yo, labels, col=bg,
... )
}
text(xy$x, xy$y, labels, col=col, ... )
}
And here is an example of use:
plot(1:10, 1:10, bg='aliceblue')
rect(3,3,5,8, col='navy')
text(5,6, 'Test 1', col='lightsteelblue')
shadowtext(5,4, 'Test 2', col='lightsteelblue')
Hope this helps,
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.snow at imail.org
801.408.8111
> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of Rodrigo Aluizio
> Sent: Friday, April 24, 2009 8:12 AM
> To: R Help
> Subject: [R] Text Contrast in a Plot
>
> Hi List,
>
> I would appreciate any suggestion on how can I make a text I've
> inserted in a plot show some contrast? With this I mean that I have a
> white text on a plot and I would like to make a tiny border around it
> in black, so even being small sized and the entire graphic being small
> in the text page I'll insert it. It will be visible.
>
>
>
> Well I tried inserting a box() function inside the text() function, R
> accepts the command but there is no effect. I even tried to plot a
> greater black text and then a smaller white one at the same place, but
> it doesn't look good.
>
>
>
> Any ideas!
>
>
>
> Bellow is my plot code without the above mentioned attempts. I'd like
> to add this effect at the second text() command.
>
>
>
> png('BaseMap.png',width=5.2,height=3.6,pointsize=5,units='in',bg=NA,res
> toreC
> onsole=T,res=1200)
>
> par(mar=c(5,0,0,0))
>
> map('worldHires','brazil',ylim=c(-5.15,-4.55),xlim=c(-37,-
> 36.1),type='n')
>
> rect(-37.1,-5.25,-36,-4.9,density=NULL,angle=45,col='#dbf4ff',border=F)
>
> plot(Batimetria,ylab='',xlab='',border=F,col=Cor$Cor,add=T)
>
> plot(Municipios,ylab='',xlab='',col=rgb(245,232,140,max=255,alpha=255),
> add=T
> ,lwd=0.2)
>
> axis(1,xaxp=c(-37,-36.1,5),cex.axis=1.5)
>
> axis(2,yaxp=c(-5.15,-4.55,5),cex.axis=1.5)
>
> text(Prof$Long,Prof$Lat,rownames(Prof),col='black',cex=0.9,srt=-
> 24,font=2)
>
> text(c(-36.96,-36.96,-36.865,-36.54,-36.37,-36.2),c(-4.96,-5.05,-5.11,-
> 5.14,
> -5.14,-5.14),c('Areia
>
> Branca','Serra
>
> do Mel','Porto do
> Mangue','Macau','Guamar?','Galinhos'),col='Black',cex=1.3,font=2)
>
> rect(-36.20,-4.56,-36.155,-
> 4.565,density=NULL,angle=45,col='black',border='b
> lack',lwd=0.1)
>
> rect(-36.155,-4.56,-36.111,-
> 4.565,density=NULL,angle=45,col='white',border='
> black',lwd=0.1)
>
> text(c(-36.20,-36.155,-36.111,-36.215),c(-4.573,-4.573,-4.573,-
> 4.562),c('0',
> '5','10','km'),col='white',cex=1)
>
> Norte(-36.155,-4.60,0.02)
>
> box(which='plot',lty='solid')
>
> dev.off()
>
>
>
> Thanks in advance!
>
>
>
> -------------------------------------------------------------
>
> MSc. <mailto:r.aluizio at gmail.com> Rodrigo Aluizio
>
> Centro de Estudos do Mar/UFPR
> Laborat?rio de Micropaleontologia
> Avenida Beira Mar s/n - CEP 83255-000
> Pontal do Paran? - PR - Brasil
>
>
> [[alternative HTML version deleted]]
Rodrigo Aluizio wrote:
Hi List, I would appreciate any suggestion on how can I make a text I?ve inserted in a plot show some contrast? With this I mean that I have a white text on a plot and I would like to make a tiny border around it in black, so even being small sized and the entire graphic being small in the text page I?ll insert it. It will be visible. Well I tried inserting a box() function inside the text() function, R accepts the command but there is no effect. I even tried to plot a greater black text and then a smaller white one at the same place, but it doesn?t look good.
Hi Rodrigo, Try boxed.labels in the plotrix package. Jim