I have a tidy dataframe with multiple models that I'm plotting as a dotwhisker plot. Below I've recreated a similar dataframe. This plot requires a caption explaining information about the predictors, and ideally it would go underneath the legend. I have tried doing this as a caption, tag, and annotation, and each time the addition of the brackets on the side causes a problem with the formatting. Is there a way to add additional text here without the brackets causing a formatting issue?
#create dataframe
results_df <- data.frame(
model = c("Model 1", "Model 1", "Model 1",
"Model 1", "Model 1", "Model 1",
"Model 2", "Model 2", "Model 2",
"Model 2", "Model 2", "Model 2",
"Model 3", "Model 3", "Model 3",
"Model 3", "Model 3", "Model 3",
"Model 2", "Model 2", "Model 2",
"Model 2", "Model 2", "Model 2",
"Model 2", "Model 2", "Model 2"),
estimate = c(-0.4890, 0.0966, -0.0911, -0.1700, 0.3620, 0.1980, -2.0920,
-1.1620, -1.6910,-1.5320, -0.8340, -1.4350, 0.8240, 0.9750,
0.9650, 0.5210, 0.9190, 0.9560, -0.9580, -0.1950, -1.1470,
-2.6430,-1.7420, -2.2500, -2.9990, -1.8100, -1.8270),
conf.low = c(-0.6, 0.0, -0.2,-0.6, 0.0, -0.2, -2.4, -1.8, -1.9, -2.4,
-1.8, -1.9, 0.0, 0.0, 0.0, 0.0, 0.0,0.0, -3.0, -2.0,
-1.9, -5.6, -3.6, -3.8, -3.0, -2.0, -1.9),
conf.high = c(0.9, 1.1, 1.0, 0.9, 1.1, 1.0, 0.0, 0.5, 0.7, 0.0, 0.5, 0.7,
0.9, 1.1, 1.0, 0.9, 1.1, 1.0, 0.0, 0.5, 0.7, 0.0,0.5, 0.7,
0.0, 0.5, 0.7),
term = c("A","B","C","A","B","C","A","B","C","A",
"B","C","A","B","C","A","B","C","D","E",
"F","G","H","I","J","K",
"L"),
fixed = c("Without Fixed Effects", "Without Fixed Effects", "Without Fixed Effects",
"With Fixed Effects", "With Fixed Effects", "With Fixed Effects",
"Without Fixed Effects", "Without Fixed Effects", "Without Fixed Effects",
"With Fixed Effects", "With Fixed Effects", "With Fixed Effects",
"Without Fixed Effects", "Without Fixed Effects", "Without Fixed Effects",
"With Fixed Effects", "With Fixed Effects", "With Fixed Effects",
"Without Fixed Effects", "Without Fixed Effects", "Without Fixed Effects",
"Without Fixed Effects", "Without Fixed Effects", "Without Fixed Effects",
"Without Fixed Effects", "Without Fixed Effects", "Without Fixed Effects"),
type = c("Model 1", "Model 1", "Model 1",
"Model 1", "Model 1", "Model 1",
"Model 2", "Model 2", "Model 2",
"Model 2", "Model 2", "Model 2",
"Model 3", "Model 3", "Model 3",
"Model 3", "Model 3", "Model 3",
"Model 2", "Model 2", "Model 2",
"Model 2", "Model 2", "Model 2",
"Model 2", "Model 2", "Model 2")
)
#recode model
results_df$model = results_df$type
#create dotwhisker
full_graph = dwplot(results_df,
vline = geom_vline(xintercept = 0, colour = "grey60", linetype = 2),
dot_args = list(aes(shape = fixed)),
whisker_args = list(aes(colour = model)))
#add graph elements
full_graph = full_graph +
theme_bw() +
theme(legend.justification=c(.02, .993),
legend.background = element_rect(color="gray90"),
plot.title = element_text(hjust = 0.52)) + #here is where I've tried using plot.caption and plot.tag, plot.tag.position
xlab("Coefficient Estimate") +
geom_vline(xintercept = 0, colour = "grey60", linetype = 2) +
ggtitle("Graph Title") +
scale_color_manual(name="Model",values=c("#52D871","#17D0E5","#EF5B3D"),
na.translate = F)+
scale_shape_manual(name = "Shape",values=c(16,17,16,17,16,17), na.translate = F)+
scale_fill_manual(name="Model",values = c("#52D871","#17D0E5","#EF5B3D"),
na.translate = F)
#add brackets
brackets = list(c("Bracket 1", "A", "C"),
c("Bracket 2", "D", "F"),
c("Bracket 3", "G", "I"),
c("Bracket 4","J","L"))
full_plot = full_graph %>% add_brackets(brackets)
Image of graph:
I'm not sure what you mean by the formatting being messed up. You could add a caption under the legend like this:
full_plot +
labs(caption = "Here's a caption explaining
what the different colors
and shapes represent ") +
theme(plot.caption = element_text(vjust = 70, hjust = 0.9, size = 12))
Related
I get a position_dodge() requires non-overlapping x intervals` warning with the following data and code. If I omit the width = 3 option then I don't get the warning but the columns are almost impossible to distinguish. The plot of the ggplot code has lots of space between each set of columns so I wonder if anyone has a suggestion on what I need to change to get ride of the warning.
library(ggplot2)
g_crop <- ggplot(cumsum_2022_melt, aes(fill = variable, y = quantity, x = as.Date(date))) +
geom_col(position="dodge", width = 3)
dput output
structure(list(date = structure(c(1657152000, 1657497600, 1657756800,
1657843200, 1658102400, 1658966400, 1659571200, 1660176000, 1660780800,
1661385600, 1661990400, 1662595200, 1663286400, 1663545600, 1664323200,
1657152000, 1657497600, 1657756800, 1657843200, 1658102400, 1658966400,
1659571200, 1660176000, 1660780800, 1661385600, 1661990400, 1662595200,
1663286400, 1663545600, 1664323200, 1657152000, 1657497600, 1657756800,
1657843200, 1658102400, 1658966400, 1659571200, 1660176000, 1660780800,
1661385600, 1661990400, 1662595200, 1663286400, 1663545600, 1664323200,
1657152000, 1657497600, 1657756800, 1657843200, 1658102400, 1658966400,
1659571200, 1660176000, 1660780800, 1661385600, 1661990400, 1662595200,
1663286400, 1663545600, 1664323200), class = c("POSIXct", "POSIXt"
), tzone = "UTC"), variable = c("chard plot 1", "chard plot 1",
"chard plot 1", "chard plot 1", "chard plot 1", "chard plot 1",
"chard plot 1", "chard plot 1", "chard plot 1", "chard plot 1",
"chard plot 1", "chard plot 1", "chard plot 1", "chard plot 1",
"chard plot 1", "chard plot 2", "chard plot 2", "chard plot 2",
"chard plot 2", "chard plot 2", "chard plot 2", "chard plot 2",
"chard plot 2", "chard plot 2", "chard plot 2", "chard plot 2",
"chard plot 2", "chard plot 2", "chard plot 2", "chard plot 2",
"chard plot 3", "chard plot 3", "chard plot 3", "chard plot 3",
"chard plot 3", "chard plot 3", "chard plot 3", "chard plot 3",
"chard plot 3", "chard plot 3", "chard plot 3", "chard plot 3",
"chard plot 3", "chard plot 3", "chard plot 3", "chard plot 4",
"chard plot 4", "chard plot 4", "chard plot 4", "chard plot 4",
"chard plot 4", "chard plot 4", "chard plot 4", "chard plot 4",
"chard plot 4", "chard plot 4", "chard plot 4", "chard plot 4",
"chard plot 4", "chard plot 4"), quantity = c(0, 0, 0, 7.4, 7.4,
17.82, 27.37, 32.32, 35.37, 38.77, 41.62, 45.27, 45.27, 48.82,
54.17, 0, 0, 0, 0.35, 0.35, 0.35, 1.7, 3.3, 4.2, 6, 7.3, 7.3,
7.3, 10, 12.4, 0, 0, 0, 1, 1, 1, 1, 4.3, 9.55, 9.55, 10.05, 12.85,
12.85, 14.65, 16.65, 0, 0, 0, 2.3, 2.3, 9, 11.75, 13.85, 16.5,
19.55, 20.45, 21.95, 21.95, 23.2, 25.65)), row.names = c(NA,
-60L), class = c("data.table", "data.frame"), .internal.selfref = <pointer: 0x135841ce0>, index = structure(integer(0), "`__variable`" = integer(0)))
I don't know what the difference is, however I always use dodge2 instead of dodge. It seems to works in your situation as well:
https://ggplot2.tidyverse.org/reference/position_dodge.html
library(ggplot2)
#g_crop <-
ggplot(cumsum_2022_melt, aes(fill = variable, y = quantity, x = as.Date(date))) +
geom_col(position="dodge2", width=3)
Something funny is happening with the bars on the left, they are smaller then the rest of the bars. Maybe due to the records with zero data? This link talks about it: Consistent width for geom_bar in the event of missing data
Trying this solution:
ggplot(cumsum_2022_melt, aes(fill = variable, y = quantity, x = as.Date(date))) +
geom_bar(position=position_dodge2(preserve = "single"), stat="identity", width=2)
The reason you are getting the warning is because ggplot2 observes that your data has daily resolution, in that it is not aligned to any longer time grid. As such, it will throw a warning when your dodging will cause a grouping to be wider than one day, since that risks the data having overlapping x intervals. It's a bit of false alarm here, since most of your groups are 7+ days from their neighbors.
Since the visualization is otherwise what you want, the warning can be safely ignored.
If you care about avoiding it, but you don't care about the precise alignment of your data to the specified dates, one option would be to align your data by week, such that ggplot recognizes that there are 7 days of width (ie width 7) that can be accommodated between groups. This doesn't throw a warning.
ggplot(cumsum_2022_melt, aes(fill = variable, y = quantity,
x = lubridate::floor_date(as.Date(date), "week"))) +
geom_col(position="dodge", width = 6)
Here is my dataset
structure(list(id_data = c("20", "63", "93", "156", "162", "177",
"38_", "44_", "57_", "63_", "73_", "79_", "105_", "111_", "154_",
"156_", "158_", "168_", "20", "63", "93", "156", "162", "177",
"38_", "44_", "57_", "63_", "73_", "79_", "105_", "111_", "154_",
"156_", "158_", "168_", "20", "63", "93", "156", "162", "177",
"38_", "44_", "57_", "63_", "73_", "79_", "105_", "111_", "154_",
"156_", "158_", "168_"), bras = c("Treatment 2", "Treatment 2",
"Treatment 2", "Treatment 2", "Treatment 2", "Treatment 2", "Treatment 1",
"Treatment 1", "Treatment 1", "Treatment 1", "Treatment 1", "Treatment 1",
"Treatment 1", "Treatment 1", "Treatment 1", "Treatment 1", "Treatment 1",
"Treatment 1", "Treatment 2", "Treatment 2", "Treatment 2", "Treatment 2",
"Treatment 2", "Treatment 2", "Treatment 1", "Treatment 1", "Treatment 1",
"Treatment 1", "Treatment 1", "Treatment 1", "Treatment 1", "Treatment 1",
"Treatment 1", "Treatment 1", "Treatment 1", "Treatment 1", "Treatment 2",
"Treatment 2", "Treatment 2", "Treatment 2", "Treatment 2", "Treatment 2",
"Treatment 1", "Treatment 1", "Treatment 1", "Treatment 1", "Treatment 1",
"Treatment 1", "Treatment 1", "Treatment 1", "Treatment 1", "Treatment 1",
"Treatment 1", "Treatment 1"), Progesterone = c(0.2, 0.21, 0.17,
0.19, 0.2, 0.46, 60, 21.6, 40.73, 34.07, 25.5, 60, 38.5, 60,
16.36, 48.7, 22, 32.73, 0.2, 0.21, 0.2, 0.25, 0.2, 0.46, 38.49,
7.22, 60, 23.03, 12.8, 57.14, 2.36, 46.1, 10.1, 14.21, 1.38,
33.58, 0.25, 0.4, 0.39, 0.3, 0.2, 0.96, 15.2, 7.55, 12.46, 6.68,
12.8, 15.92, 0.62, 2.71, 10.14, 14.21, 1.38, 2.51), Period = c("Time 1",
"Time 1", "Time 1", "Time 1", "Time 1", "Time 1", "Time 1", "Time 1",
"Time 1", "Time 1", "Time 1", "Time 1", "Time 1", "Time 1", "Time 1",
"Time 1", "Time 1", "Time 1", "Time 2", "Time 2", "Time 2", "Time 2",
"Time 2", "Time 2", "Time 2", "Time 2", "Time 2", "Time 2", "Time 2",
"Time 2", "Time 2", "Time 2", "Time 2", "Time 2", "Time 2", "Time 2",
"Time 3", "Time 3", "Time 3", "Time 3", "Time 3", "Time 3", "Time 3",
"Time 3", "Time 3", "Time 3", "Time 3", "Time 3", "Time 3", "Time 3",
"Time 3", "Time 3", "Time 3", "Time 3")), row.names = c(NA, -54L
), class = "data.frame")
I made boxplots by Treatment and period
ggplot(mydata,
aes(x=Progesterone, y=bras,fill=bras ))+
geom_boxplot()+coord_flip()+
facet_grid(cols = vars(Period))
But the difference in the magnitude of the values between the two treatments is so great that the boxplots of treatment 2 are no longer visible. I don't want to do a logarithmic transformation or normalization but rather to make the scales of the two treatment groups different (while keeping the boxplots of the two groups side by side (as in the figures below)
Do you think this is possible?
You could do this with the scale="free_y" parameter of facet_wrap, which gives you this:
ggplot(mydata, aes(x = Period, y = Progesterone, fill = bras)) +
geom_boxplot() +
facet_wrap(~bras, nrow = 1, scale = "free_y")
However, I don't recommend this. A plot like this can look very misleading, since it's easy to overlook that the scales are different. I recommend that you plot all 6 on the same scale (as in your question), and then add a clearly labelled, separate "zoomed in" panel to show the relative distributions of Treatment 2.
Incidentally, I've tidied up your ggplot a bit - there's no need to coord_flip(), just assign the coordinates you want in the first place!
I would like to overlay my plot with circles as axis to illustrate probability levels (e.g 0.25; 0.75, 1).
To reproduce the graphic you need these 2 csv files in working directory
https://drive.google.com/open?id=1RsleBYQFlm3ce3xuqTLK-_r9s374yd40
Or since I have been kindly advised by #Gregor in comments here are the headers of my data objects so no downloading is necessary:
dput(head(data))
structure(list(id = 1:6, individual = structure(c(1L, 12L, 23L,
26L, 27L, 28L), .Label = c("Person 1", "Person 10", "Person 11",
"Person 12", "Person 13", "Person 14", "Person 15", "Person 16",
"Person 17", "Person 18", "Person 19", "Person 2", "Person 20",
"Person 21", "Person 22", "Person 23", "Person 24", "Person 25",
"Person 26", "Person 27", "Person 28", "Person 29", "Person 3",
"Person 30", "Person 31", "Person 4", "Person 5", "Person 6",
"Person 7", "Person 8", "Person 9"), class = "factor"), value = c(0.658333333,
0.958333333, 0.720833334, 0.883333333, 0.779166667, 0.9375),
group = structure(c(1L, 1L, 1L, 1L, 1L, 1L), .Label = "A", class = "factor")), .Names = c("id",
"individual", "value", "group"), row.names = c(NA, 6L), class = "data.frame")
and second object:
dput(head(label_data))
structure(list(id = 1:6, individual = structure(c(1L, 12L, 23L,
26L, 27L, 28L), .Label = c("Person 1", "Person 10", "Person 11",
"Person 12", "Person 13", "Person 14", "Person 15", "Person 16",
"Person 17", "Person 18", "Person 19", "Person 2", "Person 20",
"Person 21", "Person 22", "Person 23", "Person 24", "Person 25",
"Person 26", "Person 27", "Person 28", "Person 29", "Person 3",
"Person 30", "Person 31", "Person 4", "Person 5", "Person 6",
"Person 7", "Person 8", "Person 9"), class = "factor"), value = c(0.658333333,
0.958333333, 0.720833334, 0.883333333, 0.779166667, 0.9375),
group = structure(c(1L, 1L, 1L, 1L, 1L, 1L), .Label = "A", class = "factor"),
hjust = c(0, 0, 0, 0, 0, 0), angle = c(84.375, 73.125, 61.875,
50.625, 39.375, 28.125)), .Names = c("id", "individual",
"value", "group", "hjust", "angle"), row.names = c(NA, 6L), class = "data.frame")
And then run following:
library(tidyverse)
library(ggplot2)
library(plotrix)
data=read.csv(file="data_object_2.csv", header=TRUE, sep=",")
label_data=read.csv(file="label_data_object_2.csv", header=TRUE, sep=",")
empty_bar=1
to_add = data.frame( matrix(NA, empty_bar*nlevels(data$group), ncol(data)) )
colnames(to_add) = colnames(data)
to_add$group=rep(levels(data$group), each=empty_bar)
data=rbind(data, to_add)
data=data %>% arrange(group)
data$id=seq(1, nrow(data))
number_of_bar=nrow(label_data)
angle= 90 - 360 * (label_data$id-0.5) /32
label_data$hjust<-ifelse( angle < -90, 1, 0)
label_data$angle<-ifelse(angle < -90, angle+180, angle)
p = ggplot(data, aes(x=as.factor(id), y=value)) +
geom_bar(stat="identity", fill=alpha("skyblue", 0.7)) +
ylim(-0.3,1) +
theme_minimal() +
theme(
axis.text = element_blank(),
axis.title = element_blank(),
panel.grid = element_blank(),
plot.margin = unit(rep(-1,4), "cm")
) +
coord_polar(start = 0) +
geom_text(data=label_data, aes(x=id, y=value, label=individual, hjust=hjust), color="black", fontface="bold",alpha=0.6, size=2.5, angle= label_data$angle, inherit.aes = FALSE ) +
geom_vline(xintercept = 0, color = "grey", linetype = "dashed") +
annotate("text", label = "p=0", x = 0, y = 0, color = "black") +
annotate("text", label = "p=1", x = 0, y = 1, color = "black") +
annotate("text", label = "p=0.5", x = 0, y = 0.5, color = "black")
p
It will result in this:
https://drive.google.com/open?id=1xDOym_nn-x9nrUoKpB9rtg7h7NYIfucF
I would like to overlay with circles indicating probability levels to enhance readability. All the on-line help which I have found is related to common Cartesian graph or geom_circle function which did not work either.
I will really appreciate any help.
Thanks Marek
Here's an option over a simplified version of your code (I didn't want to recreate all the labels, etc, just a pared down version of your chart). I thought about it like this: if this were in regular Cartesian coordinates, you could show an overlay of a probability by making a horizontal line, so in polar coordinates, that line would become a circle. Adding a geom_hline gives you a circle at whatever yintercept you set.
It might be good to label those probabilities; you can figure out what's the best way to do that in your context, but I just made a couple of circles, set the y-breaks to those same values, and moved the y axis title to be near the labels so they had a little explanation. Based on your context, that might not all be necessary.
As an aside, I'd recommend combining these two data frames into one, so you can more easily keep track of things and not have to set different data = arguments in different geoms.
library(tidyverse)
label_data %>%
ggplot(aes(x = individual, y = value)) +
geom_col(width = 0.5, fill = "skyblue", alpha = 0.7) +
geom_hline(yintercept = c(0.5, 0.75, 0.9), color = "gray60") +
scale_y_continuous(limits = c(-0.3, NA), breaks = c(0.5, 0.75, 0.9)) +
theme_minimal() +
theme(panel.grid = element_blank(), axis.title.y = element_text(hjust = 0.87)) +
coord_polar(start = 0) +
labs(x = NULL, y = "Probability")
Created on 2018-06-03 by the reprex package (v0.2.0).
already searched all related threads about this but could not find a solution.
Here is my code and the attached plot result:
g <-ggplot(NDVI2, aes(LAI2, NDVI, colour = Legend)) +
theme_bw (base_family = "Times") +
scale_colour_manual (values = c("purple", "green", "blue", "yellow", "magenta","orange", "cyan", "red", "black")) +
geom_point (size = 3) +
geom_smooth (aes(group = 1, colour = "Trendline"), method = "loess", size = 1, linetype = 5, se = FALSE) +
geom_smooth (aes(group = 1, colour = "Regression (log)"),linetype = 1, size=1.2,method = "lm", formula = y~ log(x), se = FALSE) +
labs (title = "Correlation of LAI and NDVI")+
theme (legend.title = element_text (size = 15))
Which results in this plot:
As you can see, all Legend Icons look the same. What I want is that the points are shown as points and the two lines ("Regression" and "Trendline") are shown as lines.
I tried to use
guides (colour = guide_legend (override.aes = list(size = 1.5)))
but that gives me again all icons in the same way and I can not figure out how to distinguish between them
I´m new to R and this is my first "complex" plot. Try to figure out most with online helps and google but can´t find a solution for this problem. Thank you all for your time and help!
Here a dput of my data:
dput(NDVI2)
structure(list(MeanRED = c(3.240264, 6.97950484, 3.75052276,
4.62617908, 4.07743944, 4.88961572, 3.15865532, 2.28368236, 3.40793788,
4.28833416, 4.52529496, 2.45698208, 3.84003364, 4.31006672, 3.29672264,
4.21926652, 4.64357012, 3.94445908, 3.95942484, 1.22673756, 4.70933136,
5.33718396, 5.71857348, 5.7014266, 3.85938572, 6.07816804, 2.93602476,
5.00289296), MeanNIR = c(46.8226195806452, 48.4417953548387,
47.8913064516129, 43.9416386774194, 44.7524788709677, 52.2142607741935,
48.6422146774194, 44.6617992580645, 57.7213822580645, 58.5066447096774,
56.6924350967742, 57.4100250967742, 58.0419292903226, 58.7054423225806,
58.5283540645161, 54.7658463548387, 58.8950077096774, 58.2421209354839,
57.8538210645161, 50.209727516129, 59.5780209354839, 60.1662100645161,
62.1929408387097, 60.3309026451613, 57.859932516129, 63.5678422258065,
55.2536370967742, 60.1808743548387), NDVI = c(0.870552242769623,
0.748129155560663, 0.854748647859414, 0.809496111062421, 0.832994214160536,
0.828746627367857, 0.878046244390978, 0.902709173224405, 0.888500710549276,
0.863417928083076, 0.852157374806182, 0.917918660181389, 0.875891666709934,
0.863206160341016, 0.893353221193523, 0.856937918252258, 0.853834622095331,
0.873141147848366, 0.871890732089488, 0.952300860559358, 0.853491201866442,
0.837040994913869, 0.831587513918106, 0.827314084928549, 0.874937512911774,
0.825455384542418, 0.899087753174211, 0.846498808949291), LAI2 = c(1.1,
1.2, 1.3, 1.4, 2.1, 2.2, 2.3, 2.4, 3.1, 3.2, 3.3, 3.4, 4.1, 4.2,
4.3, 4.4, 5.1, 5.2, 5.3, 5.4, 6.1, 6.2, 6.3, 6.4, 7.1, 7.2, 7.3,
7.4), Legend = c("LAI 1", "LAI 1", "LAI 1", "LAI 1", "LAI 2",
"LAI 2", "LAI 2", "LAI 2", "LAI 3", "LAI 3", "LAI 3", "LAI 3",
"LAI 4", "LAI 4", "LAI 4", "LAI 4", "LAI 5", "LAI 5", "LAI 5",
"LAI 5", "LAI 6", "LAI 6", "LAI 6", "LAI 6", "LAI 7", "LAI 7",
"LAI 7", "LAI 7")), .Names = c("MeanRED", "MeanNIR", "NDVI",
"LAI2", "Legend"), class = "data.frame", row.names = c("LAI 1-1",
"LAI 1-2", "LAI 1-3", "LAI 1-4", "LAI 2-1", "LAI 2-2", "LAI 2-3",
"LAI 2-4", "LAI 3-1", "LAI 3-2", "LAI 3-3", "LAI 3-4", "LAI 4-1",
"LAI 4-2", "LAI 4-3", "LAI 4-4", "LAI 5-1", "LAI 5-2", "LAI 5-3",
"LAI 5-4", "LAI 6-1", "LAI 6-2", "LAI 6-3", "LAI 6-4", "LAI 7-1",
"LAI 7-2", "LAI 7-3", "LAI 7-4"))
override.aes is definitely a good start for customizing the legend. In your case you may remove unwanted shape in the legend by setting them to NA, and set unwanted linetype to blank:
ggplot(data = NDVI2, aes(x = LAI2, y = NDVI, colour = Legend)) +
geom_point(size = 3) +
geom_smooth(aes(group = 1, colour = "Trendline"),
method = "loess", se = FALSE, linetype = "dashed") +
geom_smooth(aes(group = 1, colour = "Regression (log)"),
method = "lm", formula = y ~ log(x), se = FALSE, linetype = "solid") +
scale_colour_manual(values = c("purple", "green", "blue", "yellow", "magenta","orange", "cyan", "red", "black"),
guide = guide_legend(override.aes = list(
linetype = c(rep("blank", 7), "solid", "dashed"),
shape = c(rep(16, 7), NA, NA))))
I've created a lattice plot with three panels. I can control the font size for the axis and tick labels, but I haven't been able to figure out how to increase the font size of the strip labels. Here's a concrete example:
# See below for the fake data to run this code
library(lattice)
barchart(choice ~ yes+no+not.app|group, data=data,
stack=TRUE, col=c("green","red","blue"),
xlim=c(0,100), layout=c(3,1),
scales=list(cex=c(1.4,1.4), alternating=3),
xlab=list(label="Percent of Respondents", fontsize=20),
main="")
Here's the graph this code produces. Note how all the fonts are nice and big except for the strip labels ("Group 1", "Group 2", "Group 3"). I've been fishing around R-help and Stack Overflow, but haven't been able to work this one out. Does anyone know the magic incantation?
data = structure(list(choice = c("Choice 1", "Choice 1", "Choice 1",
"Choice 2", "Choice 2", "Choice 2", "Choice 3", "Choice 3", "Choice 3",
"Choice 4", "Choice 4", "Choice 4"), group = c("Group 1", "Group 2",
"Group 3", "Group 1", "Group 2", "Group 3", "Group 1", "Group 2",
"Group 3", "Group 1", "Group 2", "Group 3"), yes = c(23.53, 20.47,
22.94, 16.51, 16.54, 16.51, 9.68, 13.39, 10.4, 24.48, 29.92,
25.54), no = c(41.37, 37.01, 40.52, 48.39, 40.94, 46.94, 55.22,
44.09, 53.06, 40.42, 27.56, 37.92), not.app = c(35.1, 42.52,
36.54, 35.1, 42.52, 36.54, 35.1, 42.52, 36.54, 35.1, 42.52, 36.54
)), .Names = c("choice", "group", "yes", "no", "not.app"), row.names = c(NA,
12L), class = "data.frame")
Try this (good work on supplying an example):
barchart(choice ~ yes+no+not.app|group, data=data,
par.strip.text=list(cex=2),
stack=TRUE, col=c("green","red","blue"),
xlim=c(0,100), layout=c(3,1),
scales=list(cex=c(1.4,1.4), alternating=3),
xlab=list(label="Percent of Respondents", fontsize=20),
main="")
To see more about how to manage the strip features type : ?strip.default There are other levers to throw in strip.custom. Also see the latticeExtra package that has the capacity to put strips on the sides with useOuterStrips.