Re: [R] Knitr, ggplot and consistent fonts
I believe you are right. We thank either Gmail or [[alternative HTML version deleted]] for this. I think showNonASCII() is just irrelevant here and pulling us to the wrong direction. It is not reliable to paste code into Email due to the potentially wrong text wrapping. Please consider an email attachment (not sure if an Rnw document can get through), or a Github gist, or pastebin instead, e.g. https://gist.github.com/yihui/8105762 Or ask on SO: http://stackoverflow.com/questions/tagged/r Now let's move back to the original question, to which I have no solution. Regards, Yihui -- Yihui Xie Web: http://yihui.name Department of Statistics, Iowa State University 2215 Snedecor Hall, Ames, IA On Mon, Dec 23, 2013 at 10:53 AM, Federico Lasa wrote: > Hi, chiming in. > Pasted the code in R studio and the format parser wouldn't mark the R code > chunks. It was because there were line breaks in the middle of chunk > options tags. Couldn't test if removing line breaks works, but maybe > that's the source of the problem? > > > On Mon, Dec 23, 2013 at 10:37 AM, John Kane wrote: > >> Same result here with the same error message mentioned in my first post. >> I tried it in Texmaker which is my usual Latex editor, not that I do much >> in Latex, and then tried it in RStudio and it is still choking. >> >> Interestingly EMACS will process it and produce a pdf but it simply >> produces. It also provides this warning: : Latex Warning; Reference >> 'fig:plot-figheight' undefined on page 2 on input line 14. >> >> It seems to repeat the same message for each of the other figures. >> >> John Kane >> Kingston ON Canada >> >> >> > -Original Message- >> > From: dulca...@bigpond.com >> > Sent: Mon, 23 Dec 2013 22:28:33 +1000 >> > To: daniel.haugstv...@gmail.com, r-help@r-project.org >> > Subject: Re: [R] Knitr, ggplot and consistent fonts >> > >> > Hi Dan >> > >> > >> > >> > I think you still have problems with embedded characters or some problems >> > in >> > char code page conversion or the like. >> > >> > >> > >> > Not knowing knitr but Sweave I cobbled the figures manually and ran the >> > sweave file to produce the latex file. >> > >> > Latex was consistently stopping at the \caption and \ref functions >> > >> > I tried to see what was happening I added hyperref & when I copied the >> > text >> > to hyperref latex bailed up >> > >> > >> > >> > I tried a minimal latex file without problems >> > >> > >> > >> > I put the \title etc in the preamble. Some compilers need this >> > >> > >> > >> > Duncan >> > >> > >> > >> > From: Daniel Haugstvedt [mailto:daniel.haugstv...@gmail.com] >> > Sent: Monday, 23 December 2013 20:10 >> > To: Duncan Mackay >> > Cc: John Kane; R >> > Subject: Re: [R] Knitr, ggplot and consistent fonts >> > >> > >> > >> > I am really sorry for posting a non-working example. It is running when I >> > cut the code from my previous mail into a clean session in RStudio (OSX). >> > However, I suspect that you are right. I did cut and paste some code from >> > a >> > forum yesterday which had characters that had to be replaced. I gave >> > emacs a >> > try, but could not find the problem there either. >> > >> > >> > >> > The code below was pasted though textEdit and converted to plain text. I >> > hope this takes care of any embedded characters. >> > >> > >> > >> > \documentclass{article} >> > >> > \begin{document} >> > >> > >> > >> > <>= >> > >> > library(knitr) >> > >> > library(ggplot2) >> > >> > @ >> > >> > >> > >> > \title{Knitr and ggplot2} >> > >> > \author{Daniel Haugstvedt} >> > >> > >> > >> > \maketitle >> > >> > >> > >> > There are four plots in this article. Figure \ref{fig:plot-figHeight} >> > uses >> > >> > the argument fig.height=2.5 while Figures \ref{fig:plot-figWidth} >> > >> > used both fig.height=2.5 and fig.width=3. The later option makes the font >> > >> > too big. >> > >> > >> > >> > An alternative approach is used in Figures \ref{fig:plot-figO
Re: [R] Knitr, ggplot and consistent fonts
Thanks, I was not getting anything when I printed the x and so thought I was doing something wrong. Instead I just didn't seem to have a non-ASCII character. John Kane Kingston ON Canada > -Original Message- > From: murdoch.dun...@gmail.com > Sent: Mon, 23 Dec 2013 15:52:32 -0500 > To: jrkrid...@inbox.com, r...@temple.edu > Subject: Re: [R] Knitr, ggplot and consistent fonts > > On 13-12-23 1:07 PM, John Kane wrote: >> Thanks Duncan. >> I had the feeling I was doing something wrong but did not realise it was >> that stupid. >> >> showNonASCII('ggplot(df, aes(x = x)) + geom_histogram(aes(y = >> ..density..)), >> binwidth = 1, colour = "black", fill = "white")') >> >> now runs and does what the help page seems to imply: Nothing. >> >> From the showNonASCII help page: >> "The elements of x containing non-ASCII characters will be returned >> invisibly." >> >> One gets a result one does not see? Does one have to explicitly capture >> the result somehow? I really have not the faintest idea of what the >> example from the help page is doing. > > "returned invisibly" means that the result is returned with a flag set > so it won't automatically print. If you want to print it, you need to > ask. So any of these will work to see the result: > > x <- showNonASCII( ) > x > > or > > print(showNonASCII( )) > > or even (though this is one some of us don't like, it still works...) > > (showNonASCII( )) > > Duncan Murdoch > >> John Kane >> Kingston ON Canada >> >> >>> -Original Message- >>> From: murdoch.dun...@gmail.com >>> Sent: Mon, 23 Dec 2013 12:51:43 -0500 >>> To: jrkrid...@inbox.com, r...@temple.edu >>> Subject: Re: [R] Knitr, ggplot and consistent fonts >>> >>> On 13-12-23 12:40 PM, John Kane wrote: >>>> Thanks Richard. I did not realise such a function existed. >>>> >>>> Assuming I am using it correctly I do get an error though not where I >>>> was expecting it. Anyway the code below returns an error >>>> >>>> library(tools) >>>> showNonASCII("ggplot(df, aes(x = x)) + geom_histogram(aes(y = >>>> ..density..)), binwidth = 1, colour = "black", fill = "white")") >>>> >>>> Results >>>> Error: unexpected symbol in: >>>> "showNonASCII("ggplot(df, aes(x = x)) + geom_histogram(aes(y = >>>> ..density..)), binwidth = 1, colour = "black" >>> >>> You get that error because you're using double quotes around a string >>> containing double quotes, and not escaping them. With that string, >>> using single quotes on the outside should be fine: >>> >>>showNonASCII('ggplot(df, aes(x = x)) + geom_histogram(aes(y = >>> ..density..)), binwidth = 1, colour = "black", fill = "white")') >>> >>> Duncan Murdoch >>>> >>>> >>>> >>>> John Kane >>>> Kingston ON Canada >>>> >>>> >>>>> -Original Message- >>>>> From: r...@temple.edu >>>>> Sent: Mon, 23 Dec 2013 11:44:42 -0500 >>>>> To: jrkrid...@inbox.com >>>>> Subject: Re: [R] Knitr, ggplot and consistent fonts >>>>> >>>>> If the problem seems to be non-ASCII characters, then the first >>>>> investigation >>>>> step is to use the R functions >>>>> >>>>> ?tools::showNonASCII >>>>> ?tools::showNonASCIIfile >>>>> >>>>> On Mon, Dec 23, 2013 at 11:37 AM, John Kane >>>>> wrote: >>>>>> Same result here with the same error message mentioned in my first >>>>>> post. >>>>>> I tried it in Texmaker which is my usual Latex editor, not that I do >>>>>> much in Latex, and then tried it in RStudio and it is still choking. >>>>>> >>>>>> Interestingly EMACS will process it and produce a pdf but it simply >>>>>> produces. It also provides this warning: : Latex Warning; Reference >>>>>> 'fig:plot-figheight' undefined on page 2 on input line 14. >>>>>> >>>>>> It seems to repeat the same message for each of the other figures. >>>>>> >>>>>
Re: [R] Knitr, ggplot and consistent fonts
On 13-12-23 1:07 PM, John Kane wrote: Thanks Duncan. I had the feeling I was doing something wrong but did not realise it was that stupid. showNonASCII('ggplot(df, aes(x = x)) + geom_histogram(aes(y = ..density..)), binwidth = 1, colour = "black", fill = "white")') now runs and does what the help page seems to imply: Nothing. From the showNonASCII help page: "The elements of x containing non-ASCII characters will be returned invisibly." One gets a result one does not see? Does one have to explicitly capture the result somehow? I really have not the faintest idea of what the example from the help page is doing. "returned invisibly" means that the result is returned with a flag set so it won't automatically print. If you want to print it, you need to ask. So any of these will work to see the result: x <- showNonASCII( ) x or print(showNonASCII( )) or even (though this is one some of us don't like, it still works...) (showNonASCII( )) Duncan Murdoch John Kane Kingston ON Canada -Original Message- From: murdoch.dun...@gmail.com Sent: Mon, 23 Dec 2013 12:51:43 -0500 To: jrkrid...@inbox.com, r...@temple.edu Subject: Re: [R] Knitr, ggplot and consistent fonts On 13-12-23 12:40 PM, John Kane wrote: Thanks Richard. I did not realise such a function existed. Assuming I am using it correctly I do get an error though not where I was expecting it. Anyway the code below returns an error library(tools) showNonASCII("ggplot(df, aes(x = x)) + geom_histogram(aes(y = ..density..)), binwidth = 1, colour = "black", fill = "white")") Results Error: unexpected symbol in: "showNonASCII("ggplot(df, aes(x = x)) + geom_histogram(aes(y = ..density..)), binwidth = 1, colour = "black" You get that error because you're using double quotes around a string containing double quotes, and not escaping them. With that string, using single quotes on the outside should be fine: showNonASCII('ggplot(df, aes(x = x)) + geom_histogram(aes(y = ..density..)), binwidth = 1, colour = "black", fill = "white")') Duncan Murdoch John Kane Kingston ON Canada -Original Message- From: r...@temple.edu Sent: Mon, 23 Dec 2013 11:44:42 -0500 To: jrkrid...@inbox.com Subject: Re: [R] Knitr, ggplot and consistent fonts If the problem seems to be non-ASCII characters, then the first investigation step is to use the R functions ?tools::showNonASCII ?tools::showNonASCIIfile On Mon, Dec 23, 2013 at 11:37 AM, John Kane wrote: Same result here with the same error message mentioned in my first post. I tried it in Texmaker which is my usual Latex editor, not that I do much in Latex, and then tried it in RStudio and it is still choking. Interestingly EMACS will process it and produce a pdf but it simply produces. It also provides this warning: : Latex Warning; Reference 'fig:plot-figheight' undefined on page 2 on input line 14. It seems to repeat the same message for each of the other figures. John Kane Kingston ON Canada -----Original Message----- From: dulca...@bigpond.com Sent: Mon, 23 Dec 2013 22:28:33 +1000 To: daniel.haugstv...@gmail.com, r-help@r-project.org Subject: Re: [R] Knitr, ggplot and consistent fonts Hi Dan I think you still have problems with embedded characters or some problems in char code page conversion or the like. Not knowing knitr but Sweave I cobbled the figures manually and ran the sweave file to produce the latex file. Latex was consistently stopping at the \caption and \ref functions I tried to see what was happening I added hyperref & when I copied the text to hyperref latex bailed up I tried a minimal latex file without problems I put the \title etc in the preamble. Some compilers need this Duncan From: Daniel Haugstvedt [mailto:daniel.haugstv...@gmail.com] Sent: Monday, 23 December 2013 20:10 To: Duncan Mackay Cc: John Kane; R Subject: Re: [R] Knitr, ggplot and consistent fonts I am really sorry for posting a non-working example. It is running when I cut the code from my previous mail into a clean session in RStudio (OSX). However, I suspect that you are right. I did cut and paste some code from a forum yesterday which had characters that had to be replaced. I gave emacs a try, but could not find the problem there either. The code below was pasted though textEdit and converted to plain text. I hope this takes care of any embedded characters. \documentclass{article} \begin{document} <>= library(knitr) library(ggplot2) @ \title{Knitr and ggplot2} \author{Daniel Haugstvedt} \maketitle There are four plots in this article. Figure \ref{fig:plot-figHeight} uses the argument fig.height=2.5 while Figures \ref{fig:plot-figWidth} used both fig.height=2.5 and fig.width=3. The later option makes the font too big.
Re: [R] Knitr, ggplot and consistent fonts
Hi, chiming in. Pasted the code in R studio and the format parser wouldn't mark the R code chunks. It was because there were line breaks in the middle of chunk options tags. Couldn't test if removing line breaks works, but maybe that's the source of the problem? On Mon, Dec 23, 2013 at 10:37 AM, John Kane wrote: > Same result here with the same error message mentioned in my first post. > I tried it in Texmaker which is my usual Latex editor, not that I do much > in Latex, and then tried it in RStudio and it is still choking. > > Interestingly EMACS will process it and produce a pdf but it simply > produces. It also provides this warning: : Latex Warning; Reference > 'fig:plot-figheight' undefined on page 2 on input line 14. > > It seems to repeat the same message for each of the other figures. > > John Kane > Kingston ON Canada > > > > -Original Message- > > From: dulca...@bigpond.com > > Sent: Mon, 23 Dec 2013 22:28:33 +1000 > > To: daniel.haugstv...@gmail.com, r-help@r-project.org > > Subject: Re: [R] Knitr, ggplot and consistent fonts > > > > Hi Dan > > > > > > > > I think you still have problems with embedded characters or some problems > > in > > char code page conversion or the like. > > > > > > > > Not knowing knitr but Sweave I cobbled the figures manually and ran the > > sweave file to produce the latex file. > > > > Latex was consistently stopping at the \caption and \ref functions > > > > I tried to see what was happening I added hyperref & when I copied the > > text > > to hyperref latex bailed up > > > > > > > > I tried a minimal latex file without problems > > > > > > > > I put the \title etc in the preamble. Some compilers need this > > > > > > > > Duncan > > > > > > > > From: Daniel Haugstvedt [mailto:daniel.haugstv...@gmail.com] > > Sent: Monday, 23 December 2013 20:10 > > To: Duncan Mackay > > Cc: John Kane; R > > Subject: Re: [R] Knitr, ggplot and consistent fonts > > > > > > > > I am really sorry for posting a non-working example. It is running when I > > cut the code from my previous mail into a clean session in RStudio (OSX). > > However, I suspect that you are right. I did cut and paste some code from > > a > > forum yesterday which had characters that had to be replaced. I gave > > emacs a > > try, but could not find the problem there either. > > > > > > > > The code below was pasted though textEdit and converted to plain text. I > > hope this takes care of any embedded characters. > > > > > > > > \documentclass{article} > > > > \begin{document} > > > > > > > > <>= > > > > library(knitr) > > > > library(ggplot2) > > > > @ > > > > > > > > \title{Knitr and ggplot2} > > > > \author{Daniel Haugstvedt} > > > > > > > > \maketitle > > > > > > > > There are four plots in this article. Figure \ref{fig:plot-figHeight} > > uses > > > > the argument fig.height=2.5 while Figures \ref{fig:plot-figWidth} > > > > used both fig.height=2.5 and fig.width=3. The later option makes the font > > > > too big. > > > > > > > > An alternative approach is used in Figures \ref{fig:plot-figOutWidthBig} > > and > > > > \ref{fig:plot-figOutWidthSmall}. There the argument out.width is set to > > > > 12 and 8 cm respectively. This stops the problem of excessively large > > fonts > > > > for figures with smaller width, but there is still no consistency > > > > across plots in terms o font size. > > > > > > > > <>= > > > > df = data.frame(x = rnorm(100), y = 1:100) > > > > ggplot(df, aes(x = x)) + > > > > geom_histogram(aes(y = ..density..), > > > > binwidth = 1, colour = "black", fill = "white") + > > > > xlab("Improvement, %") + > > > > ylab("Density") + > > > > theme_classic() > > > > @ > > > > > > > > < > fig.cap="Density > > plot with fig.width=3", fig.pos='ht'>>= > > > > ggplot(df, aes(x = x)) + > > > > geom_histogram(aes(y = ..density..), > > > > binwidth = 1, colour = "black", fill = "white") + > > > > xlab("Improvement,
Re: [R] Knitr, ggplot and consistent fonts
Thanks Duncan. I had the feeling I was doing something wrong but did not realise it was that stupid. showNonASCII('ggplot(df, aes(x = x)) + geom_histogram(aes(y = ..density..)), binwidth = 1, colour = "black", fill = "white")') now runs and does what the help page seems to imply: Nothing. >From the showNonASCII help page: "The elements of x containing non-ASCII characters will be returned invisibly. " One gets a result one does not see? Does one have to explicitly capture the result somehow? I really have not the faintest idea of what the example from the help page is doing. John Kane Kingston ON Canada > -Original Message- > From: murdoch.dun...@gmail.com > Sent: Mon, 23 Dec 2013 12:51:43 -0500 > To: jrkrid...@inbox.com, r...@temple.edu > Subject: Re: [R] Knitr, ggplot and consistent fonts > > On 13-12-23 12:40 PM, John Kane wrote: >> Thanks Richard. I did not realise such a function existed. >> >> Assuming I am using it correctly I do get an error though not where I >> was expecting it. Anyway the code below returns an error >> >> library(tools) >> showNonASCII("ggplot(df, aes(x = x)) + geom_histogram(aes(y = >> ..density..)), binwidth = 1, colour = "black", fill = "white")") >> >> Results >> Error: unexpected symbol in: >> "showNonASCII("ggplot(df, aes(x = x)) + geom_histogram(aes(y = >> ..density..)), binwidth = 1, colour = "black" > > You get that error because you're using double quotes around a string > containing double quotes, and not escaping them. With that string, > using single quotes on the outside should be fine: > > showNonASCII('ggplot(df, aes(x = x)) + geom_histogram(aes(y = > ..density..)), binwidth = 1, colour = "black", fill = "white")') > > Duncan Murdoch >> >> >> >> John Kane >> Kingston ON Canada >> >> >>> -Original Message- >>> From: r...@temple.edu >>> Sent: Mon, 23 Dec 2013 11:44:42 -0500 >>> To: jrkrid...@inbox.com >>> Subject: Re: [R] Knitr, ggplot and consistent fonts >>> >>> If the problem seems to be non-ASCII characters, then the first >>> investigation >>> step is to use the R functions >>> >>> ?tools::showNonASCII >>> ?tools::showNonASCIIfile >>> >>> On Mon, Dec 23, 2013 at 11:37 AM, John Kane >>> wrote: >>>> Same result here with the same error message mentioned in my first >>>> post. >>>> I tried it in Texmaker which is my usual Latex editor, not that I do >>>> much in Latex, and then tried it in RStudio and it is still choking. >>>> >>>> Interestingly EMACS will process it and produce a pdf but it simply >>>> produces. It also provides this warning: : Latex Warning; Reference >>>> 'fig:plot-figheight' undefined on page 2 on input line 14. >>>> >>>> It seems to repeat the same message for each of the other figures. >>>> >>>> John Kane >>>> Kingston ON Canada >>>> >>>> >>>>> -Original Message- >>>>> From: dulca...@bigpond.com >>>>> Sent: Mon, 23 Dec 2013 22:28:33 +1000 >>>>> To: daniel.haugstv...@gmail.com, r-help@r-project.org >>>>> Subject: Re: [R] Knitr, ggplot and consistent fonts >>>>> >>>>> Hi Dan >>>>> >>>>> >>>>> >>>>> I think you still have problems with embedded characters or some >>>>> problems >>>>> in >>>>> char code page conversion or the like. >>>>> >>>>> >>>>> >>>>> Not knowing knitr but Sweave I cobbled the figures manually and ran >>>>> the >>>>> sweave file to produce the latex file. >>>>> >>>>> Latex was consistently stopping at the \caption and \ref functions >>>>> >>>>> I tried to see what was happening I added hyperref & when I copied >>>>> the >>>>> text >>>>> to hyperref latex bailed up >>>>> >>>>> >>>>> >>>>> I tried a minimal latex file without problems >>>>> >>>>> >>>>> >>>>> I put the \title etc in the preamble. Some compilers need this >>>>> >>>>> >>>>> >>>
Re: [R] Knitr, ggplot and consistent fonts
On 13-12-23 12:40 PM, John Kane wrote: Thanks Richard. I did not realise such a function existed. Assuming I am using it correctly I do get an error though not where I was expecting it. Anyway the code below returns an error library(tools) showNonASCII("ggplot(df, aes(x = x)) + geom_histogram(aes(y = ..density..)), binwidth = 1, colour = "black", fill = "white")") Results Error: unexpected symbol in: "showNonASCII("ggplot(df, aes(x = x)) + geom_histogram(aes(y = ..density..)), binwidth = 1, colour = "black" You get that error because you're using double quotes around a string containing double quotes, and not escaping them. With that string, using single quotes on the outside should be fine: showNonASCII('ggplot(df, aes(x = x)) + geom_histogram(aes(y = ..density..)), binwidth = 1, colour = "black", fill = "white")') Duncan Murdoch John Kane Kingston ON Canada -Original Message- From: r...@temple.edu Sent: Mon, 23 Dec 2013 11:44:42 -0500 To: jrkrid...@inbox.com Subject: Re: [R] Knitr, ggplot and consistent fonts If the problem seems to be non-ASCII characters, then the first investigation step is to use the R functions ?tools::showNonASCII ?tools::showNonASCIIfile On Mon, Dec 23, 2013 at 11:37 AM, John Kane wrote: Same result here with the same error message mentioned in my first post. I tried it in Texmaker which is my usual Latex editor, not that I do much in Latex, and then tried it in RStudio and it is still choking. Interestingly EMACS will process it and produce a pdf but it simply produces. It also provides this warning: : Latex Warning; Reference 'fig:plot-figheight' undefined on page 2 on input line 14. It seems to repeat the same message for each of the other figures. John Kane Kingston ON Canada -Original Message- From: dulca...@bigpond.com Sent: Mon, 23 Dec 2013 22:28:33 +1000 To: daniel.haugstv...@gmail.com, r-help@r-project.org Subject: Re: [R] Knitr, ggplot and consistent fonts Hi Dan I think you still have problems with embedded characters or some problems in char code page conversion or the like. Not knowing knitr but Sweave I cobbled the figures manually and ran the sweave file to produce the latex file. Latex was consistently stopping at the \caption and \ref functions I tried to see what was happening I added hyperref & when I copied the text to hyperref latex bailed up I tried a minimal latex file without problems I put the \title etc in the preamble. Some compilers need this Duncan From: Daniel Haugstvedt [mailto:daniel.haugstv...@gmail.com] Sent: Monday, 23 December 2013 20:10 To: Duncan Mackay Cc: John Kane; R Subject: Re: [R] Knitr, ggplot and consistent fonts I am really sorry for posting a non-working example. It is running when I cut the code from my previous mail into a clean session in RStudio (OSX). However, I suspect that you are right. I did cut and paste some code from a forum yesterday which had characters that had to be replaced. I gave emacs a try, but could not find the problem there either. The code below was pasted though textEdit and converted to plain text. I hope this takes care of any embedded characters. \documentclass{article} \begin{document} <>= library(knitr) library(ggplot2) @ \title{Knitr and ggplot2} \author{Daniel Haugstvedt} \maketitle There are four plots in this article. Figure \ref{fig:plot-figHeight} uses the argument fig.height=2.5 while Figures \ref{fig:plot-figWidth} used both fig.height=2.5 and fig.width=3. The later option makes the font too big. An alternative approach is used in Figures \ref{fig:plot-figOutWidthBig} and \ref{fig:plot-figOutWidthSmall}. There the argument out.width is set to 12 and 8 cm respectively. This stops the problem of excessively large fonts for figures with smaller width, but there is still no consistency across plots in terms o font size. <>= df = data.frame(x = rnorm(100), y = 1:100) ggplot(df, aes(x = x)) + geom_histogram(aes(y = ..density..), binwidth = 1, colour = "black", fill = "white") + xlab("Improvement, %") + ylab("Density") + theme_classic() @ <>= ggplot(df, aes(x = x)) + geom_histogram(aes(y = ..density..), binwidth = 1, colour = "black", fill = "white") + xlab("Improvement, %") + ylab("Density") + theme_classic() @ <>= ggplot(df, aes(x = x)) + geom_histogram(aes(y = ..density..), binwidth = 1, colour = "black", fill = "white") + xlab("Improvement, %") + ylab("Density") + theme_classic() @ <>= ggplot(df, aes(x = x)) + geom_histogram(aes(y = ..density..), binwidth = 1, colour = "black",
Re: [R] Knitr, ggplot and consistent fonts
Thanks Richard. I did not realise such a function existed. Assuming I am using it correctly I do get an error though not where I was expecting it. Anyway the code below returns an error library(tools) showNonASCII("ggplot(df, aes(x = x)) + geom_histogram(aes(y = ..density..)), binwidth = 1, colour = "black", fill = "white")") Results Error: unexpected symbol in: "showNonASCII("ggplot(df, aes(x = x)) + geom_histogram(aes(y = ..density..)), binwidth = 1, colour = "black" John Kane Kingston ON Canada > -Original Message- > From: r...@temple.edu > Sent: Mon, 23 Dec 2013 11:44:42 -0500 > To: jrkrid...@inbox.com > Subject: Re: [R] Knitr, ggplot and consistent fonts > > If the problem seems to be non-ASCII characters, then the first > investigation > step is to use the R functions > > ?tools::showNonASCII > ?tools::showNonASCIIfile > > On Mon, Dec 23, 2013 at 11:37 AM, John Kane wrote: >> Same result here with the same error message mentioned in my first post. >> I tried it in Texmaker which is my usual Latex editor, not that I do >> much in Latex, and then tried it in RStudio and it is still choking. >> >> Interestingly EMACS will process it and produce a pdf but it simply >> produces. It also provides this warning: : Latex Warning; Reference >> 'fig:plot-figheight' undefined on page 2 on input line 14. >> >> It seems to repeat the same message for each of the other figures. >> >> John Kane >> Kingston ON Canada >> >> >>> -----Original Message- >>> From: dulca...@bigpond.com >>> Sent: Mon, 23 Dec 2013 22:28:33 +1000 >>> To: daniel.haugstv...@gmail.com, r-help@r-project.org >>> Subject: Re: [R] Knitr, ggplot and consistent fonts >>> >>> Hi Dan >>> >>> >>> >>> I think you still have problems with embedded characters or some >>> problems >>> in >>> char code page conversion or the like. >>> >>> >>> >>> Not knowing knitr but Sweave I cobbled the figures manually and ran the >>> sweave file to produce the latex file. >>> >>> Latex was consistently stopping at the \caption and \ref functions >>> >>> I tried to see what was happening I added hyperref & when I copied the >>> text >>> to hyperref latex bailed up >>> >>> >>> >>> I tried a minimal latex file without problems >>> >>> >>> >>> I put the \title etc in the preamble. Some compilers need this >>> >>> >>> >>> Duncan >>> >>> >>> >>> From: Daniel Haugstvedt [mailto:daniel.haugstv...@gmail.com] >>> Sent: Monday, 23 December 2013 20:10 >>> To: Duncan Mackay >>> Cc: John Kane; R >>> Subject: Re: [R] Knitr, ggplot and consistent fonts >>> >>> >>> >>> I am really sorry for posting a non-working example. It is running when >>> I >>> cut the code from my previous mail into a clean session in RStudio >>> (OSX). >>> However, I suspect that you are right. I did cut and paste some code >>> from >>> a >>> forum yesterday which had characters that had to be replaced. I gave >>> emacs a >>> try, but could not find the problem there either. >>> >>> >>> >>> The code below was pasted though textEdit and converted to plain text. >>> I >>> hope this takes care of any embedded characters. >>> >>> >>> >>> \documentclass{article} >>> >>> \begin{document} >>> >>> >>> >>> <>= >>> >>> library(knitr) >>> >>> library(ggplot2) >>> >>> @ >>> >>> >>> >>> \title{Knitr and ggplot2} >>> >>> \author{Daniel Haugstvedt} >>> >>> >>> >>> \maketitle >>> >>> >>> >>> There are four plots in this article. Figure \ref{fig:plot-figHeight} >>> uses >>> >>> the argument fig.height=2.5 while Figures \ref{fig:plot-figWidth} >>> >>> used both fig.height=2.5 and fig.width=3. The later option makes the >>> font >>> >>> too big. >>> >>> >>> >>> An alternative approach is used in Figures >>> \ref{fig:plot-figOutWidthBig} >>> and >>> >>> \ref{fig:plot-figO
Re: [R] Knitr, ggplot and consistent fonts
Does not seem to be. I 'think' I removed all the line breaks and it still is not compiling. Thanks for the suggestion. I had not bothered to paste the <<>>= text into RStudio and since TexMaker has an automatic wrap, I would never have noticed it. John Kane Kingston ON Canada -Original Message- From: fel...@gmail.com Sent: Mon, 23 Dec 2013 10:53:59 -0600 To: jrkrid...@inbox.com Subject: Re: [R] Knitr, ggplot and consistent fonts Hi, chiming in. Pasted the code in R studio and the format parser wouldn't mark the R code chunks. It was because there were line breaks in the middle of chunk options tags. Couldn't test if removing line breaks works, but maybe that's the source of the problem? On Mon, Dec 23, 2013 at 10:37 AM, John Kane wrote: Same result here with the same error message mentioned in my first post. I tried it in Texmaker which is my usual Latex editor, not that I do much in Latex, and then tried it in RStudio and it is still choking. Interestingly EMACS will process it and produce a pdf but it simply produces. It also provides this warning: : Latex Warning; Reference 'fig:plot-figheight' undefined on page 2 on input line 14. It seems to repeat the same message for each of the other figures. John Kane Kingston ON Canada > -Original Message- > From: dulca...@bigpond.com > Sent: Mon, 23 Dec 2013 22:28:33 +1000 > To: daniel.haugstv...@gmail.com, r-help@r-project.org > Subject: Re: [R] Knitr, ggplot and consistent fonts > > Hi Dan > > > > I think you still have problems with embedded characters or some problems > in > char code page conversion or the like. > > > > Not knowing knitr but Sweave I cobbled the figures manually and ran the > sweave file to produce the latex file. > > Latex was consistently stopping at the \caption and \ref functions > > I tried to see what was happening I added hyperref & when I copied the > text > to hyperref latex bailed up > > > > I tried a minimal latex file without problems > > > > I put the \title etc in the preamble. Some compilers need this > > > > Duncan > > > > From: Daniel Haugstvedt [mailto:daniel.haugstv...@gmail.com] > Sent: Monday, 23 December 2013 20:10 > To: Duncan Mackay > Cc: John Kane; R > Subject: Re: [R] Knitr, ggplot and consistent fonts > > > > I am really sorry for posting a non-working example. It is running when I > cut the code from my previous mail into a clean session in RStudio (OSX). > However, I suspect that you are right. I did cut and paste some code from > a > forum yesterday which had characters that had to be replaced. I gave > emacs a > try, but could not find the problem there either. > > > > The code below was pasted though textEdit and converted to plain text. I > hope this takes care of any embedded characters. > > > > \documentclass{article} > > \begin{document} > > > > <>= > > library(knitr) > > library(ggplot2) > > @ > > > > \title{Knitr and ggplot2} > > \author{Daniel Haugstvedt} > > > > \maketitle > > > > There are four plots in this article. Figure \ref{fig:plot-figHeight} > uses > > the argument fig.height=2.5 while Figures \ref{fig:plot-figWidth} > > used both fig.height=2.5 and fig.width=3. The later option makes the font > > too big. > > > > An alternative approach is used in Figures \ref{fig:plot-figOutWidthBig} > and > > \ref{fig:plot-figOutWidthSmall}. There the argument out.width is set to > > 12 and 8 cm respectively. This stops the problem of excessively large > fonts > > for figures with smaller width, but there is still no consistency > > across plots in terms o font size. > > > > <>= > > df = data.frame(x = rnorm(100), y = 1:100) > > ggplot(df, aes(x = x)) + > > geom_histogram(aes(y = ..density..), > > binwidth = 1, colour = "black", fill = "white") + > > xlab("Improvement, %") + > > ylab("Density") + > > theme_classic() > > @ > > > > < fig.cap="Density > plot with fig.width=3", fig.pos='ht'>>= > > ggplot(df, aes(x = x)) + > > geom_histogram(aes(y = ..density..), > > binwidth = 1, colour = "black", fill = "white") + > > xlab("Improvement, %") + > > ylab("Density") + > > theme_classic() > > @ > > > > < fig.
Re: [R] Knitr, ggplot and consistent fonts
If the problem seems to be non-ASCII characters, then the first investigation step is to use the R functions ?tools::showNonASCII ?tools::showNonASCIIfile On Mon, Dec 23, 2013 at 11:37 AM, John Kane wrote: > Same result here with the same error message mentioned in my first post. I > tried it in Texmaker which is my usual Latex editor, not that I do much in > Latex, and then tried it in RStudio and it is still choking. > > Interestingly EMACS will process it and produce a pdf but it simply produces. > It also provides this warning: : Latex Warning; Reference > 'fig:plot-figheight' undefined on page 2 on input line 14. > > It seems to repeat the same message for each of the other figures. > > John Kane > Kingston ON Canada > > >> -Original Message- >> From: dulca...@bigpond.com >> Sent: Mon, 23 Dec 2013 22:28:33 +1000 >> To: daniel.haugstv...@gmail.com, r-help@r-project.org >> Subject: Re: [R] Knitr, ggplot and consistent fonts >> >> Hi Dan >> >> >> >> I think you still have problems with embedded characters or some problems >> in >> char code page conversion or the like. >> >> >> >> Not knowing knitr but Sweave I cobbled the figures manually and ran the >> sweave file to produce the latex file. >> >> Latex was consistently stopping at the \caption and \ref functions >> >> I tried to see what was happening I added hyperref & when I copied the >> text >> to hyperref latex bailed up >> >> >> >> I tried a minimal latex file without problems >> >> >> >> I put the \title etc in the preamble. Some compilers need this >> >> >> >> Duncan >> >> >> >> From: Daniel Haugstvedt [mailto:daniel.haugstv...@gmail.com] >> Sent: Monday, 23 December 2013 20:10 >> To: Duncan Mackay >> Cc: John Kane; R >> Subject: Re: [R] Knitr, ggplot and consistent fonts >> >> >> >> I am really sorry for posting a non-working example. It is running when I >> cut the code from my previous mail into a clean session in RStudio (OSX). >> However, I suspect that you are right. I did cut and paste some code from >> a >> forum yesterday which had characters that had to be replaced. I gave >> emacs a >> try, but could not find the problem there either. >> >> >> >> The code below was pasted though textEdit and converted to plain text. I >> hope this takes care of any embedded characters. >> >> >> >> \documentclass{article} >> >> \begin{document} >> >> >> >> <>= >> >> library(knitr) >> >> library(ggplot2) >> >> @ >> >> >> >> \title{Knitr and ggplot2} >> >> \author{Daniel Haugstvedt} >> >> >> >> \maketitle >> >> >> >> There are four plots in this article. Figure \ref{fig:plot-figHeight} >> uses >> >> the argument fig.height=2.5 while Figures \ref{fig:plot-figWidth} >> >> used both fig.height=2.5 and fig.width=3. The later option makes the font >> >> too big. >> >> >> >> An alternative approach is used in Figures \ref{fig:plot-figOutWidthBig} >> and >> >> \ref{fig:plot-figOutWidthSmall}. There the argument out.width is set to >> >> 12 and 8 cm respectively. This stops the problem of excessively large >> fonts >> >> for figures with smaller width, but there is still no consistency >> >> across plots in terms o font size. >> >> >> >> <>= >> >> df = data.frame(x = rnorm(100), y = 1:100) >> >> ggplot(df, aes(x = x)) + >> >> geom_histogram(aes(y = ..density..), >> >> binwidth = 1, colour = "black", fill = "white") + >> >> xlab("Improvement, %") + >> >> ylab("Density") + >> >> theme_classic() >> >> @ >> >> >> >> <> fig.cap="Density >> plot with fig.width=3", fig.pos='ht'>>= >> >> ggplot(df, aes(x = x)) + >> >> geom_histogram(aes(y = ..density..), >> >> binwidth = 1, colour = "black", fill = "white") + >> >> xlab("Improvement, %") + >> >> ylab("Density") + >> >> theme_classic() >> >> @ >> >> >> >> <> fig.cap="Density plot with out.width=12cm", fig.pos='ht'>>= >> >> gg
Re: [R] Knitr, ggplot and consistent fonts
Same result here with the same error message mentioned in my first post. I tried it in Texmaker which is my usual Latex editor, not that I do much in Latex, and then tried it in RStudio and it is still choking. Interestingly EMACS will process it and produce a pdf but it simply produces. It also provides this warning: : Latex Warning; Reference 'fig:plot-figheight' undefined on page 2 on input line 14. It seems to repeat the same message for each of the other figures. John Kane Kingston ON Canada > -Original Message- > From: dulca...@bigpond.com > Sent: Mon, 23 Dec 2013 22:28:33 +1000 > To: daniel.haugstv...@gmail.com, r-help@r-project.org > Subject: Re: [R] Knitr, ggplot and consistent fonts > > Hi Dan > > > > I think you still have problems with embedded characters or some problems > in > char code page conversion or the like. > > > > Not knowing knitr but Sweave I cobbled the figures manually and ran the > sweave file to produce the latex file. > > Latex was consistently stopping at the \caption and \ref functions > > I tried to see what was happening I added hyperref & when I copied the > text > to hyperref latex bailed up > > > > I tried a minimal latex file without problems > > > > I put the \title etc in the preamble. Some compilers need this > > > > Duncan > > > > From: Daniel Haugstvedt [mailto:daniel.haugstv...@gmail.com] > Sent: Monday, 23 December 2013 20:10 > To: Duncan Mackay > Cc: John Kane; R > Subject: Re: [R] Knitr, ggplot and consistent fonts > > > > I am really sorry for posting a non-working example. It is running when I > cut the code from my previous mail into a clean session in RStudio (OSX). > However, I suspect that you are right. I did cut and paste some code from > a > forum yesterday which had characters that had to be replaced. I gave > emacs a > try, but could not find the problem there either. > > > > The code below was pasted though textEdit and converted to plain text. I > hope this takes care of any embedded characters. > > > > \documentclass{article} > > \begin{document} > > > > <>= > > library(knitr) > > library(ggplot2) > > @ > > > > \title{Knitr and ggplot2} > > \author{Daniel Haugstvedt} > > > > \maketitle > > > > There are four plots in this article. Figure \ref{fig:plot-figHeight} > uses > > the argument fig.height=2.5 while Figures \ref{fig:plot-figWidth} > > used both fig.height=2.5 and fig.width=3. The later option makes the font > > too big. > > > > An alternative approach is used in Figures \ref{fig:plot-figOutWidthBig} > and > > \ref{fig:plot-figOutWidthSmall}. There the argument out.width is set to > > 12 and 8 cm respectively. This stops the problem of excessively large > fonts > > for figures with smaller width, but there is still no consistency > > across plots in terms o font size. > > > > <>= > > df = data.frame(x = rnorm(100), y = 1:100) > > ggplot(df, aes(x = x)) + > > geom_histogram(aes(y = ..density..), > > binwidth = 1, colour = "black", fill = "white") + > > xlab("Improvement, %") + > > ylab("Density") + > > theme_classic() > > @ > > > > < fig.cap="Density > plot with fig.width=3", fig.pos='ht'>>= > > ggplot(df, aes(x = x)) + > > geom_histogram(aes(y = ..density..), > > binwidth = 1, colour = "black", fill = "white") + > > xlab("Improvement, %") + > > ylab("Density") + > > theme_classic() > > @ > > > > < fig.cap="Density plot with out.width=12cm", fig.pos='ht'>>= > > ggplot(df, aes(x = x)) + > > geom_histogram(aes(y = ..density..), > > binwidth = 1, colour = "black", fill = "white") + > > xlab("Improvement, %") + > > ylab("Density") + > > theme_classic() > > @ > > > > < fig.cap="Density plot with out.width=8cm", fig.pos='ht'>>= > > ggplot(df, aes(x = x)) + > > geom_histogram(aes(y = ..density..), > > binwidth = 1, colour = "black", fill = "white") + > > xlab("Improvement, %") + > > ylab("Density") + > > theme_classic() > > @ > > > > \end{document} > > > > > > > > &g
Re: [R] Knitr, ggplot and consistent fonts
Hi Dan I think you still have problems with embedded characters or some problems in char code page conversion or the like. Not knowing knitr but Sweave I cobbled the figures manually and ran the sweave file to produce the latex file. Latex was consistently stopping at the \caption and \ref functions I tried to see what was happening I added hyperref & when I copied the text to hyperref latex bailed up I tried a minimal latex file without problems I put the \title etc in the preamble. Some compilers need this Duncan From: Daniel Haugstvedt [mailto:daniel.haugstv...@gmail.com] Sent: Monday, 23 December 2013 20:10 To: Duncan Mackay Cc: John Kane; R Subject: Re: [R] Knitr, ggplot and consistent fonts I am really sorry for posting a non-working example. It is running when I cut the code from my previous mail into a clean session in RStudio (OSX). However, I suspect that you are right. I did cut and paste some code from a forum yesterday which had characters that had to be replaced. I gave emacs a try, but could not find the problem there either. The code below was pasted though textEdit and converted to plain text. I hope this takes care of any embedded characters. \documentclass{article} \begin{document} <>= library(knitr) library(ggplot2) @ \title{Knitr and ggplot2} \author{Daniel Haugstvedt} \maketitle There are four plots in this article. Figure \ref{fig:plot-figHeight} uses the argument fig.height=2.5 while Figures \ref{fig:plot-figWidth} used both fig.height=2.5 and fig.width=3. The later option makes the font too big. An alternative approach is used in Figures \ref{fig:plot-figOutWidthBig} and \ref{fig:plot-figOutWidthSmall}. There the argument out.width is set to 12 and 8 cm respectively. This stops the problem of excessively large fonts for figures with smaller width, but there is still no consistency across plots in terms o font size. <>= df = data.frame(x = rnorm(100), y = 1:100) ggplot(df, aes(x = x)) + geom_histogram(aes(y = ..density..), binwidth = 1, colour = "black", fill = "white") + xlab("Improvement, %") + ylab("Density") + theme_classic() @ <>= ggplot(df, aes(x = x)) + geom_histogram(aes(y = ..density..), binwidth = 1, colour = "black", fill = "white") + xlab("Improvement, %") + ylab("Density") + theme_classic() @ <>= ggplot(df, aes(x = x)) + geom_histogram(aes(y = ..density..), binwidth = 1, colour = "black", fill = "white") + xlab("Improvement, %") + ylab("Density") + theme_classic() @ <>= ggplot(df, aes(x = x)) + geom_histogram(aes(y = ..density..), binwidth = 1, colour = "black", fill = "white") + xlab("Improvement, %") + ylab("Density") + theme_classic() @ \end{document} On Sun, Dec 22, 2013 at 11:59 PM, Duncan Mackay wrote: Hi Daniel I tried it in Sweave after modifying it for Sweave and a similar thing for Latex but R crashed. I think there is an embedded character/s before the first chunk and in the first chunk. Duncan Duncan Mackay Department of Agronomy and Soil Science University of New England Armidale NSW 2351 Email: home: mac...@northnet.com.au -Original Message----- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of John Kane Sent: Monday, 23 December 2013 04:19 To: Daniel Haugstvedt; r-help@r-project.org Subject: Re: [R] Knitr, ggplot and consistent fonts Hi Daniel, For some reason I cannot get your example to work. The problem is in the code chunk but I have no idea what is happening. The code is running perfectly in R, itself but LaTeX seems to be choking when it hits the first ggplot statement, that is the one in <>= The message I am getting is: "Missing $ inserted $ ggplot(df, aes(x=x)) = geom_" and my knowledge of LateX is not enough to figure out the problem. I tried stripping out most of the LaTeX specific verbiage in the code chunk and running the code in LyX which I use rather than plain vanilla LaTeX and I still cannot get it to work. It is almost as if there is some hidden character in the in that piece of code since I can duplicate the code myself and I even pasted in most of the geom_histogram code into my code chunk and it runs. John Kane Kingston ON Canada > -Original Message- > From: daniel.haugstv...@gmail.com > Sent: Sun, 22 Dec 2013 12:42:50 +0100 > To: r-help@r-project.org > Subject: [R] Knitr, ggplot and consistent fonts > > Dear R-help > > I am using Knitr and ggplot to draft an article and have now started > to improve on the layout and graphics. So far I have not been able to > maintain the
Re: [R] Knitr, ggplot and consistent fonts
I am really sorry for posting a non-working example. It is running when I cut the code from my previous mail into a clean session in RStudio (OSX). However, I suspect that you are right. I did cut and paste some code from a forum yesterday which had characters that had to be replaced. I gave emacs a try, but could not find the problem there either. The code below was pasted though textEdit and converted to plain text. I hope this takes care of any embedded characters. \documentclass{article} \begin{document} <>= library(knitr) library(ggplot2) @ \title{Knitr and ggplot2} \author{Daniel Haugstvedt} \maketitle There are four plots in this article. Figure \ref{fig:plot-figHeight} uses the argument fig.height=2.5 while Figures \ref{fig:plot-figWidth} used both fig.height=2.5 and fig.width=3. The later option makes the font too big. An alternative approach is used in Figures \ref{fig:plot-figOutWidthBig} and \ref{fig:plot-figOutWidthSmall}. There the argument out.width is set to 12 and 8 cm respectively. This stops the problem of excessively large fonts for figures with smaller width, but there is still no consistency across plots in terms o font size. <>= df = data.frame(x = rnorm(100), y = 1:100) ggplot(df, aes(x = x)) + geom_histogram(aes(y = ..density..), binwidth = 1, colour = "black", fill = "white") + xlab("Improvement, %") + ylab("Density") + theme_classic() @ <>= ggplot(df, aes(x = x)) + geom_histogram(aes(y = ..density..), binwidth = 1, colour = "black", fill = "white") + xlab("Improvement, %") + ylab("Density") + theme_classic() @ <>= ggplot(df, aes(x = x)) + geom_histogram(aes(y = ..density..), binwidth = 1, colour = "black", fill = "white") + xlab("Improvement, %") + ylab("Density") + theme_classic() @ <>= ggplot(df, aes(x = x)) + geom_histogram(aes(y = ..density..), binwidth = 1, colour = "black", fill = "white") + xlab("Improvement, %") + ylab("Density") + theme_classic() @ \end{document} On Sun, Dec 22, 2013 at 11:59 PM, Duncan Mackay wrote: > Hi Daniel > I tried it in Sweave after modifying it for Sweave and a similar thing for > Latex but R crashed. > > I think there is an embedded character/s before the first chunk and in the > first chunk. > > Duncan > > Duncan Mackay > Department of Agronomy and Soil Science > University of New England > Armidale NSW 2351 > Email: home: mac...@northnet.com.au > > -Original Message- > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] > On Behalf Of John Kane > Sent: Monday, 23 December 2013 04:19 > To: Daniel Haugstvedt; r-help@r-project.org > Subject: Re: [R] Knitr, ggplot and consistent fonts > > Hi Daniel, > > For some reason I cannot get your example to work. The problem is in the > code chunk but I have no idea what is happening. The code is running > perfectly in R, itself but LaTeX seems to be choking when it hits the first > ggplot statement, that is the one in <>= > > The message I am getting is: "Missing $ inserted $ > ggplot(df, aes(x=x)) = geom_" and my knowledge of LateX is not enough to > figure out the problem. > > I tried stripping out most of the LaTeX specific verbiage in the code > chunk and running the code in LyX which I use rather than plain vanilla > LaTeX and I still cannot get it to work. It is almost as if there is some > hidden character in the in that piece of code since I can duplicate the > code myself and I even pasted in most of the geom_histogram code into my > code chunk and it runs. > > John Kane > Kingston ON Canada > > > > -Original Message- > > From: daniel.haugstv...@gmail.com > > Sent: Sun, 22 Dec 2013 12:42:50 +0100 > > To: r-help@r-project.org > > Subject: [R] Knitr, ggplot and consistent fonts > > > > Dear R-help > > > > I am using Knitr and ggplot to draft an article and have now started > > to improve on the layout and graphics. So far I have not been able to > > maintain the same font size for labels in all my figures. > > > > My goal is to be able to change the width of the figures while > > maintaining the same font. This works for the height parameter > > (example not included). > > > > In the true document I also use tikz, but the problem can be > > reproduced without it. > > > > I know the question is very specific, but my understanding is that > > this combination of packages is common. (They are really great. Keep > > up the good work.) There has to be others facing the same proble
Re: [R] Knitr, ggplot and consistent fonts
Hi Daniel I tried it in Sweave after modifying it for Sweave and a similar thing for Latex but R crashed. I think there is an embedded character/s before the first chunk and in the first chunk. Duncan Duncan Mackay Department of Agronomy and Soil Science University of New England Armidale NSW 2351 Email: home: mac...@northnet.com.au -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of John Kane Sent: Monday, 23 December 2013 04:19 To: Daniel Haugstvedt; r-help@r-project.org Subject: Re: [R] Knitr, ggplot and consistent fonts Hi Daniel, For some reason I cannot get your example to work. The problem is in the code chunk but I have no idea what is happening. The code is running perfectly in R, itself but LaTeX seems to be choking when it hits the first ggplot statement, that is the one in <>= The message I am getting is: "Missing $ inserted $ ggplot(df, aes(x=x)) = geom_" and my knowledge of LateX is not enough to figure out the problem. I tried stripping out most of the LaTeX specific verbiage in the code chunk and running the code in LyX which I use rather than plain vanilla LaTeX and I still cannot get it to work. It is almost as if there is some hidden character in the in that piece of code since I can duplicate the code myself and I even pasted in most of the geom_histogram code into my code chunk and it runs. John Kane Kingston ON Canada > -Original Message- > From: daniel.haugstv...@gmail.com > Sent: Sun, 22 Dec 2013 12:42:50 +0100 > To: r-help@r-project.org > Subject: [R] Knitr, ggplot and consistent fonts > > Dear R-help > > I am using Knitr and ggplot to draft an article and have now started > to improve on the layout and graphics. So far I have not been able to > maintain the same font size for labels in all my figures. > > My goal is to be able to change the width of the figures while > maintaining the same font. This works for the height parameter > (example not included). > > In the true document I also use tikz, but the problem can be > reproduced without it. > > I know the question is very specific, but my understanding is that > this combination of packages is common. (They are really great. Keep > up the good work.) There has to be others facing the same problem and > someone must have found a nice solution. > > Additional attempts from my side which failed are not included in the > example. I have tested the Google results i could find without any luck. > > Cheers > Daniel > > PS. I know the example plots could have been smaller, but they just > became too ugly for me > > > \documentclass{article} > \begin{document} > > <>= > library(knitr) > library(ggplot2) > @ > > \title{Knitr and ggplot2} > \author{Daniel Haugstvedt} > > \maketitle > > There are four plots in this article. Figure \ref{fig:plot-figHeight} > uses the argument fig.height=2.5 while Figures \ref{fig:plot-figWidth} > used both fig.height=2.5 and fig.width=3. The later option makes the > font too big. > > An alternative approach is used in Figures > \ref{fig:plot-figOutWidthBig} and \ref{fig:plot-figOutWidthSmall}. > There the argument out.width is set to > 12 and 8 cm respectively. This stops the problem of excessively large > fonts for figures with smaller width, but there is still no > consistency across plots in terms of font size. > > <>= df = data.frame(x = > rnorm(100), y = 1:100) ggplot(df, aes(x = x)) + > geom_histogram(aes(y = ..density..), > binwidth = 1, colour = "black", fill = "white") + > xlab("Improvement, %") + > ylab("Density") + > theme_classic() > @ > > < fig.cap="Density plot with fig.width=3", fig.pos='ht'>>= ggplot(df, > aes(x = x)) + > geom_histogram(aes(y = ..density..), > binwidth = 1, colour = "black", fill = "white") + > xlab("Improvement, %") + > ylab("Density") + > theme_classic() > @ > > < fig.cap="Density plot with out.width=12cm", fig.pos='ht'>>= ggplot(df, > aes(x = x)) + > geom_histogram(aes(y = ..density..), > binwidth = 1, colour = "black", fill = "white") + > xlab("Improvement, %") + > ylab("Density") + > theme_classic() > @ > > < "8cm", fig.cap="Density plot with out.width=8cm", fig.pos='ht'>>= > ggplot(df, aes(x = x)) + > geom_histogram(aes(y = ..density..), > binwidth = 1, colour = "black", fill = "white") + > xlab(&
Re: [R] Knitr, ggplot and consistent fonts
Hi Daniel, For some reason I cannot get your example to work. The problem is in the code chunk but I have no idea what is happening. The code is running perfectly in R, itself but LaTeX seems to be choking when it hits the first ggplot statement, that is the one in <>= The message I am getting is: "Missing $ inserted $ ggplot(df, aes(x=x)) = geom_" and my knowledge of LateX is not enough to figure out the problem. I tried stripping out most of the LaTeX specific verbiage in the code chunk and running the code in LyX which I use rather than plain vanilla LaTeX and I still cannot get it to work. It is almost as if there is some hidden character in the in that piece of code since I can duplicate the code myself and I even pasted in most of the geom_histogram code into my code chunk and it runs. John Kane Kingston ON Canada > -Original Message- > From: daniel.haugstv...@gmail.com > Sent: Sun, 22 Dec 2013 12:42:50 +0100 > To: r-help@r-project.org > Subject: [R] Knitr, ggplot and consistent fonts > > Dear R-help > > I am using Knitr and ggplot to draft an article and have now started to > improve on the layout and graphics. So far I have not been able to > maintain > the same font size for labels in all my figures. > > My goal is to be able to change the width of the figures while > maintaining > the same font. This works for the height parameter (example not > included). > > In the true document I also use tikz, but the problem can be reproduced > without it. > > I know the question is very specific, but my understanding is that this > combination of packages is common. (They are really great. Keep up the > good work.) There has to be others facing the same problem and someone > must have found a nice solution. > > Additional attempts from my side which failed are not included in the > example. I have tested the Google results i could find without any luck. > > Cheers > Daniel > > PS. I know the example plots could have been smaller, but they just > became > too ugly for me > > > \documentclass{article} > \begin{document} > > <>= > library(knitr) > library(ggplot2) > @ > > \title{Knitr and ggplot2} > \author{Daniel Haugstvedt} > > \maketitle > > There are four plots in this article. Figure \ref{fig:plot-figHeight} > uses > the argument fig.height=2.5 while Figures \ref{fig:plot-figWidth} > used both fig.height=2.5 and fig.width=3. The later option makes the font > too big. > > An alternative approach is used in Figures \ref{fig:plot-figOutWidthBig} > and > \ref{fig:plot-figOutWidthSmall}. There the argument out.width is set to > 12 and 8 cm respectively. This stops the problem of excessively large > fonts > for figures with smaller width, but there is still no consistency > across plots in terms of font size. > > <>= > df = data.frame(x = rnorm(100), y = 1:100) > ggplot(df, aes(x = x)) + > geom_histogram(aes(y = ..density..), > binwidth = 1, colour = "black", fill = "white") + > xlab("Improvement, %") + > ylab("Density") + > theme_classic() > @ > > < fig.cap="Density plot with fig.width=3", fig.pos='ht'>>= > ggplot(df, aes(x = x)) + > geom_histogram(aes(y = ..density..), > binwidth = 1, colour = "black", fill = "white") + > xlab("Improvement, %") + > ylab("Density") + > theme_classic() > @ > > < fig.cap="Density plot with out.width=12cm", fig.pos='ht'>>= > ggplot(df, aes(x = x)) + > geom_histogram(aes(y = ..density..), > binwidth = 1, colour = "black", fill = "white") + > xlab("Improvement, %") + > ylab("Density") + > theme_classic() > @ > > < fig.cap="Density plot with out.width=8cm", fig.pos='ht'>>= > ggplot(df, aes(x = x)) + > geom_histogram(aes(y = ..density..), > binwidth = 1, colour = "black", fill = "white") + > xlab("Improvement, %") + > ylab("Density") + > theme_classic() > @ > > \end{document} > > [[alternative HTML version deleted]] > > __ > R-help@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. GET FREE SMILEYS FOR YOUR IM & EMAIL - Learn more at http://www.inbox.com/smileys Works with AIM®, MSN® Messenger, Yahoo!® Messenger, ICQ®, Google Talk™ and most webmails __ R-help@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.