[R] ggplot2 Increase font size
Ista Zahn
istazahn at gmail.com
Tue Feb 26 19:32:48 CET 2013
Are you sure you didn't get you threads mixed up? Your original
question was about changing font size and background colors...
See inline for answers to this new question.
On Tue, Feb 26, 2013 at 12:45 PM, Alaios <alaios at yahoo.com> wrote:
> Hi,
> I am not quite sure what you meanΙ. I give again reproducible code:
>
>
> require(ggplot2)
> require(reshape)
> DataToPlot<-matrix(data=rnorm(9),nrow=3,dimnames=list(seq(1,3),seq(4,6)))
> tdm<-melt(DataToPlot)
> p<- ggplot(tdm, aes(x = X2, y = X1, fill = factor(value))) +
> labs(x = "MHz", y = "Threshold", fill = "Duty Cycle") +
> geom_raster(alpha=1) +
>
> scale_fill_discrete(h.start=1,breaks=c(0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1),labels=c(0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1))
> +
>
> scale_x_continuous(expand = c(0, 0)) +
> scale_y_continuous(expand = c(0, 0))
>
>
>
>
>
>
> DataToPlot in my case contains something like that:
>
> DataToPlot
> 4 5 6
> 1 -0.4135124 0.4643110 -0.7530622
> 2 0.8827643 -0.1702428 0.4607671
> 3 0.7942167 -1.2450487 -0.9380290
>
>
Translating from English:
> what I would like to have is to have one specific color for each of the
> following cases c(0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1)
>
> so for example the -0.4 would be categorized under the 0 category
> the 0.46 would be categorized under the 0.5 category
> the -0.75 would be categorized under the 0 category
> the 0.88 would be categorized under the 0.9 category
to R:
tdm <- within(tdm,{
value <- ifelse(value < 0, 0, value)
value <- ifelse(value > 1, 1, value)
value <-factor(round(value, digits=1), levels=seq(0, 1, by=.1))
})
ggplot(tdm, aes(x = Var2, y = Var1, fill = value)) +
labs(x = "MHz", y = "Threshold", fill = "Duty Cycle") +
geom_raster(alpha=1) +
scale_fill_discrete(h.start=1, drop=FALSE) +
scale_x_continuous(expand = c(0, 0)) +
scale_y_continuous(expand = c(0, 0))
tdm <- within(tdm,{
value <- ifelse(value < 0, 0, value)
value <- ifelse(value > 1, 1, value)
value <-factor(round(value, digits=1))
})
>
>
> right now the code I gave prints no color bar.
because the breaks on your discrete scale don't match the actual
levels of your data...
If I change it like that.
> p<- ggplot(tdm, aes(x = X2, y = X1, fill = factor(value))) +
> labs(x = "MHz", y = "Threshold", fill = "Duty Cycle") +
>
> geom_raster(alpha=1) +
> scale_fill_discrete(h.start=1) +
> scale_x_continuous(expand = c(0, 0)) +
> scale_y_continuous(expand = c(0, 0))
>
>
> colorbar comes back but as you will see the defined values is not how I want
> to categorize my data.
So categorize your data properly.
> what I would like to have is to have one specific color for each of the
> following cases c(0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1)
>
> so for example the -0.4 would be categorized under the 0 category
> the 0.46 would be categorized under the 0.5 category
> the -0.75 would be categorized under the 0 category
> the 0.88 would be categorized under the 0.9 category
>
> Could you please help me find what I do not understand here?
Not sure, but what I don't understand is why you're following up to a
question about font sizes and background colors with a question about
factor levels.
Best,
Ista
>
> I would like to thank you in advance for your reply
>
> Regards
> Alex
>
>
> ________________________________
> From: Ista Zahn <istazahn at gmail.com>
> To: Alaios <alaios at yahoo.com>
> Cc: R help <R-help at r-project.org>
> Sent: Monday, February 25, 2013 3:54 PM
> Subject: Re: [R] ggplot2 Increase font size
>
> Hi Alex,
>
> See ?theme
>
> Best,
> Ista
>
> On Mon, Feb 25, 2013 at 9:44 AM, Alaios <alaios at yahoo.com> wrote:
>>
>> Dear all,
>> I am using the code as below
>> tdm <- melt(matrixToPlot)
>> p<- ggplot(tdm, aes(x = Var2, y = Var1, fill = factor(value))) +
>> labs(x = "Mz", y = "T", fill = "D") +
>> geom_raster(alpha=1) +
>> scale_fill_discrete(h.start=1) +
>> scale_x_continuous(expand = c(0, 0)) +
>> scale_y_continuous(expand = c(0, 0))
>>
>> to plot an two dimensional image .
>>
>> I would like to ask your help to replace the gray border with white color
>> and increase the font size of x and y axis as wells as the legend of the
>> color bar. Could you please give me the function names to use?
>>
>> Regards
>> Alex
>> [[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.
>>
>
>
More information about the R-help
mailing list