Can somebody help me to implement following plotting style?

2,089 views
Skip to first unread message

Christofer Bogaso

unread,
Dec 1, 2012, 1:27:21 AM12/1/12
to ggp...@googlegroups.com
Dear all,

I was trying to achieve following style as in
'http://stackoverflow.com/questions/12675147/how-can-we-make-xkcd-style-graphs-in-r'.
Below are the underlying codes:

library(ggplot2)
library(extrafont)

### Already have read in fonts (see previous answer on how to do this)
loadfonts()

### Set up the trial dataset
data <- NULL
data$x <- seq(1, 10, 0.1)
data$y1 <- sin(data$x)
data$y2 <- cos(data$x)
data$xaxis <- -1.5

data <- as.data.frame(data)

### XKCD theme
theme_xkcd <- theme(
panel.background = element_rect(fill="white"),
axis.ticks = element_line(colour=NA),
panel.grid = element_line(colour="white"),
axis.text.y = element_text(colour=NA),
axis.text.x = element_text(colour="black"),
text = element_text(size=16, family="Humor Sans")
)

### Plot the chart
p <- ggplot(data=data, aes(x=x, y=y1))+
geom_line(aes(y=y2), position="jitter")+
geom_line(colour="white", size=3, position="jitter")+
geom_line(colour="red", size=1, position="jitter")+
geom_text(family="Humor Sans", x=6, y=-1.2, label="A SIN AND COS CURVE")+
geom_line(aes(y=xaxis), position = position_jitter(h = 0.005),
colour="black")+
scale_x_continuous(breaks=c(2, 5, 6, 9),
labels = c("YARD", "STEPS", "DOOR", "INSIDE"))+labs(x="", y="")+
theme_xkcd


However I am not getting the 'Humor Sans' font-effect. I am getting
following Warning message:

> p
Warning messages:
1: In grid.Call(L_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
Font family not found in Windows font database
2: In grid.Call(L_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
Font family not found in Windows font database
3: In grid.Call(L_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
Font family not found in Windows font database
4: In grid.Call(L_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
Font family not found in Windows font database
5: In grid.Call(L_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
Font family not found in Windows font database
6: In grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, :
Font family not found in Windows font database
7: In grid.Call(L_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
Font family not found in Windows font database


However I have checked that, I have installed the font 'Humor Sans'
onto my machine (i.e. this font is there in the 'Windows -->> Fonts'
folder). I am using R 2.15.1 in Windows 7 machine.

Can somebody help me where my implementation went wrong?

Thanks and regards,

Ista Zahn

unread,
Dec 20, 2012, 11:07:34 AM12/20/12
to Aybek Khodiev, ggp...@googlegroups.com
I'm on a Mac so it might be different, but try

font_import()

then

fonts()

to list fonts R knows about. Change the font family in theme_xkcd if needed.

Best,
Ista

On Wed, Dec 19, 2012 at 11:23 PM, Aybek Khodiev <akho...@gmail.com> wrote:
> Hi,
>
> Could you manage it as I have the same problem and have no solution yet?
>
> Rgds,
>
> Barabek
>
>
> On Saturday, December 1, 2012 11:27:21 AM UTC+5, Bogaso wrote:
>>
>> Dear all,
>>
>> I was trying to achieve following style as in
>>
>> 'http://stackoverflow.com/questions/12675147/how-can-we-make-xkcd-style-graphs-in-r'.
>> Below are the underlying codes:
>>
>> library(ggplot2)
>> library(extrafont)
>>
>> ### Already have read in fonts (see previous answer on how to do this)
>> loadfonts()
>>
>> ### Set up the trial dataset
>> data <- NULL
>> data$x <- seq(1, 10, 0.1)
>> data$y1 <- sin(data$x)
>>
> ............................
>>
>>
>> However I have checked that, I have installed the font 'Humor Sans'
>> onto my machine (i.e. this font is there in the 'Windows -->> Fonts'
>> folder). I am using R 2.15.1 in Windows 7 machine.
>>
>> Can somebody help me where my implementation went wrong?
>>
>> Thanks and regards,
>
> --
> You received this message because you are subscribed to the ggplot2 mailing
> list.
> Please provide a reproducible example:
> https://github.com/hadley/devtools/wiki/Reproducibility
>
> To post: email ggp...@googlegroups.com
> To unsubscribe: email ggplot2+u...@googlegroups.com
> More options: http://groups.google.com/group/ggplot2

Christofer Bogaso

unread,
Dec 20, 2012, 11:06:39 AM12/20/12
to Aybek Khodiev, ggp...@googlegroups.com
No luck yet! Still waiting for someone's reply.

Thanks and regards,

On 12/20/12, Aybek Khodiev <akho...@gmail.com> wrote:
> Hi,
>
> Could you manage it as I have the same problem and have no solution yet?
>
> Rgds,
>
> Barabek
>
> On Saturday, December 1, 2012 11:27:21 AM UTC+5, Bogaso wrote:
>>
>> Dear all,
>>
>> I was trying to achieve following style as in
>> '
>> http://stackoverflow.com/questions/12675147/how-can-we-make-xkcd-style-graphs-in-r'.
>>
>>
>> Below are the underlying codes:
>>
>> library(ggplot2)
>> library(extrafont)
>>
>> ### Already have read in fonts (see previous answer on how to do this)
>> loadfonts()
>>
>> ### Set up the trial dataset
>> data <- NULL
>> data$x <- seq(1, 10, 0.1)
>> data$y1 <- sin(data$x)
>>
>> ............................
>
>>
>> However I have checked that, I have installed the font 'Humor Sans'
>> onto my machine (i.e. this font is there in the 'Windows -->> Fonts'
>> folder). I am using R 2.15.1 in Windows 7 machine.
>>
>> Can somebody help me where my implementation went wrong?
>>
>> Thanks and regards,
>>
>

Aybek Khodiev

unread,
Dec 21, 2012, 10:11:35 AM12/21/12
to Ista Zahn, ggp...@googlegroups.com
Solution is below

http://stackoverflow.com/questions/13989644/xkcd-style-graph-error-with-registered-fonts


--
Aybek V. Khodiev, MD, PhD
BTRP/TADR Training specialist, TMC/BNI
Amir Temur Str. 107B, Block C
International Business Center, Tashkent, Uzbekistan
Tel: (+998 71) 120 44 25; Fax: (+998 71) 120 44 30
Mob: (+998 97) 110 87 66
E-mail: akho...@gmail.com
Reply all
Reply to author
Forward
0 new messages