ggplot plotting vertical lines only? - r

When entering the following code, I get a weird ggplot where it plots vertical lines.
ggplot(data = otherdata, aes(x = subject, y = pct_.below)) + geom_point(aes(colour = subgroup))
When doing geom_point rather than geom_line, I get the other graph. I have no idea why this happens. There are more points than there are subgroups but that's not the solution to the issue. What do I do to fix this ggplot?
# dummy data
set.seed(45)
df <- data.frame(x=rep(1:5, 9), val=sample(1:100, 45),
variable=rep(paste0("category", 1:9), each=5))
# plot
ggplot(data = df, aes(x=x, y=val)) + geom_line(aes(colour=variable))
That code that I just posted works but I have no idea what the difference is between the two codes.
First 20 rows of the data:
structure(list(subject = structure(c(1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("Algebra II",
"Biology I", "Chemistry", "English I", "English II", "English III",
"Geometry", "Int Math I", "Int Math II", "Int Math III", "US History"
), class = "factor"), pct_.below = c(0, 12.5, 12.4, 12.5, 0,
0, 12.5, 8.4, 11.1, 12.8, 11.9, 0, 11.5, 9, 100, 66.7, 100, 100,
100, 50), subgroup = structure(c(2L, 3L, 4L, 5L, 7L, 10L, 11L,
12L, 13L, 15L, 16L, 17L, 18L, 19L, 3L, 4L, 5L, 8L, 10L, 11L), .Label = c("All Students",
"Asian", "Black or African Amer", "Black/Hispanic/Native Amer",
"ED", "English Learner T 1-2", "English Learner T 1-4", "English Learners",
"English Learners with T 1-2", "English Learners with T 1-4",
"Hispanic", "Non-Black/Hispanic/Native Amer", "Non-ED", "Non-English Learners/T 1-2",
"Non-English Learners/T 1-4", "Non-Students with Disabilities",
"Students with Disabilities", "Super Subgroup", "White"), class = "factor")), row.names = c(2L,
3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 32L,
33L, 34L, 35L, 36L, 37L), class = "data.frame")

Related

Plot Y values against the time grouped by an ID

I want make a time series plot grouped by ID. My dataset has 42 different IDs with 7 different timeframes. The timeframe varies per ID and ranges from 9/2016 to 8/2018. I.e., ID1 can start 10/2016 and end 7/2017 (with 7 rows containing a different date) and ID40 can start 11/2016 and ends 6/2018 (also with 7 rows containing a different date). I try to plot this with the following code
p <- ggplot(data = df6, aes(x = START, y = AI, col = ID, group = ID))
p + geom_point(size = 1.2,
alpha = .8) + stat_smooth(aes(group = 1)) + stat_summary(aes(group = 1), geom =
"point", fun.y = mean,
shape = 17, size = 3) + theme_minimal() + theme(axis.text.x = element_text(angle =
90, vjust = 0.5, hjust=1))
This gives me the following graph:
As one can see the X-axis is not chronological. I should start at 09/2016 and end at 08/2018 and then correspond with the Y value based on the ID. I got the following dataset:
structure(list(ID = c("ID1", "ID1", "ID1", "ID1", "ID1", "ID1",
"ID1", "ID10", "ID10", "ID10", "ID10", "ID10", "ID10", "ID10",
"ID11", "ID11", "ID11", "ID11", "ID11", "ID12"), Time = c("1",
"2", "3", "4", "5", "6", "7", "1", "2", "3", "4", "5", "6", "7",
"1", "2", "3", "4", "5", "1"), AI = c(0.393672183448241, 0.4876954603533,
0.411717908455957, 0.309769862660288, 0.149826889496538, 0.2448558592586,
0.123606753324621, 0.296109333767922, 0.309960002123076, 0.445886231347992,
0.370013553008003, 0.393414429902431, 0.318940511323733, 0.131112361225666,
0.31961673567578, 0.227268892979164, 0.433471105477564, 0.207184572401005,
0.144257239122978, 0.520204263001733), AI_VAR = c(0.154977788020905,
0.237846862049217, 0.169511636143347, 0.0959573678125739, 0.0224480968162077,
0.0599543918132674, 0.0152786294674538, 0.0876807375444826, 0.0960752029161373,
0.198814531305715, 0.136910029409606, 0.154774913655455, 0.101723049763444,
0.0171904512661696, 0.102154857724042, 0.0516511497159746, 0.187897199283942,
0.0429254470409874, 0.020810151039384, 0.270612475245176), activity = c(0,
0.303472222222222, 0.232638888888889, 0.228472222222222, 0.348611111111111,
0.215972222222222, 0.123611111111111, 0.357638888888889, 0.235416666666667,
0.233333333333333, 0.2875, 0.353472222222222, 0.356944444444444,
0.149305555555556, 0.448611111111111, 0.213888888888889, 0.248611111111111,
0.288888888888889, 0.25625, 0.238888888888889), ZIM_SD = c(0,
0.148002025121106, 0.095781596758851, 0.0707738088994687, 0.0522313184217097,
0.0528820640482116, 0.0152791681192935, 0.105900213118389, 0.0729697504998075,
0.104040120647865, 0.106378896489801, 0.139061072791901, 0.113844043625277,
0.0195758039329988, 0.143383618921218, 0.0486102909983211, 0.107765733167339,
0.059853320915846, 0.036965917525263, 0.124271018383747), ZIM_VAR = c(0,
0.0721799157746582, 0.039434998686126, 0.0219235930627339, 0.00782565597342798,
0.0129484832318932, 0.00188860836472692, 0.0313580415523671,
0.0226177040198407, 0.0463900573046668, 0.0393616334552618, 0.0547086326740462,
0.0363094774850072, 0.00256662987654616, 0.0458278042289798,
0.0110476070225835, 0.0467133314886466, 0.0124006847007297, 0.00533260120384214,
0.0646463135307921), CHECK = c(10L, 13L, 11L, 7L, 7L, 5L, 4L,
36L, 36L, 34L, 34L, 32L, 29L, 21L, 28L, 27L, 26L, 25L, 21L, 36L
), BULBAR = c(2L, 4L, 4L, 4L, 4L, 2L, 2L, 9L, 9L, 9L, 9L, 9L,
7L, 6L, 12L, 12L, 11L, 11L, 11L, 11L), FINE = c(0L, 0L, 0L, 0L,
0L, 0L, 0L, 9L, 9L, 8L, 8L, 7L, 6L, 4L, 2L, 1L, 1L, 1L, 0L, 7L
), GROSS = c(2L, 2L, 2L, 2L, 2L, 2L, 1L, 9L, 9L, 9L, 9L, 8L,
8L, 6L, 3L, 3L, 3L, 3L, 2L, 6L), RESPI = c(6L, 7L, 5L, 1L, 1L,
1L, 1L, 9L, 9L, 8L, 8L, 8L, 8L, 5L, 11L, 11L, 11L, 10L, 8L, 12L
), GROSS_RENEWD = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 6L, 6L, 6L, 6L,
5L, 5L, 4L, 3L, 3L, 3L, 3L, 2L, 3L), ACTIVE = c(2L, 2L, 2L, 2L,
2L, 2L, 1L, 18L, 18L, 17L, 17L, 15L, 14L, 10L, 5L, 4L, 4L, 4L,
2L, 13L), NON.ACTIVE = c(8L, 11L, 9L, 5L, 5L, 3L, 3L, 18L, 18L,
17L, 17L, 17L, 15L, 11L, 23L, 23L, 22L, 21L, 19L, 23L), START = c("09/2016",
"11/2016", "01/2017", "04/2017", "06/2017", "10/2017", "02/2018",
"10/2016", "12/2016", "02/2017", "04/2017", "07/2017", "11/2017",
"04/2018", "10/2016", "12/2016", "02/2017", "04/2017", "07/2017",
"10/2016"), STOP = c("10/2016", "11/2016", "01/2017", "04/2017",
"06/2017", "10/2017", "03/2018", "10/2016", "12/2016", "02/2017",
"04/2017", "07/2017", "11/2017", "04/2018", "10/2016", "12/2016",
"02/2017", "04/2017", "07/2017", "10/2016")), row.names = c(NA,
20L), class = "data.frame")
In general I want the column START to start with the begin date and end with the last date when it is plotted
You should convert your "START" column to a date format. You could use the package zoo with the function as.yearmon for that. To start the axis with your start date and end it with the end date, you could create a vector of date breaks using the min (start) date and max (end) date. Here is a reproducible example:
library(ggplot2)
library(zoo)
library(dplyr)
df6 <- df6 %>%
mutate(START = as.Date(as.yearmon(START, format = '%m/%Y')))
breaks.vec <- c(min(df6$START),
seq(from=min(df6$START), to=max(df6$START), by = 'month'))
ggplot(data = df6, aes(x = START, y = AI, col = ID, group = ID)) +
geom_point(size = 1.2, alpha = .8) +
stat_smooth(aes(group = 1)) +
stat_summary(aes(group = 1), geom = "point", fun.y = mean, shape = 17, size = 3) +
scale_x_date(breaks = breaks.vec, date_labels = "%m/%Y") +
theme_minimal() +
theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1))
#> Warning: `fun.y` is deprecated. Use `fun` instead.
#> `geom_smooth()` using method = 'loess' and formula 'y ~ x'
Created on 2022-10-17 with reprex v2.0.2

xAxis order of R highcharter column plot

With the following data frame:
dta <- structure(list(sociodemographic_var = structure(c(3L, 6L, 7L,
8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 18L, 19L, 20L, 21L, 22L,
23L, 24L, 26L, 18L, 20L, 21L, 26L, 13L, 16L, 21L, 22L, 26L, 26L,
9L, 13L, 17L, 18L, 20L, 21L, 23L, 26L, 20L, 26L), levels = c("1st grade",
"2nd grade", "3rd grade", "4th grade", "5th grade", "6th grade",
"7th grade", "8th grade", "9th grade", "10th grade", "11th grade",
"12th grade, no diploma", "High school graduate", "GED or equivalent",
"Some college, no degree", "Less than 1 year of college credit/post-secondary education (or less than 10 classes)",
"One year or more of college credit, no degree", "Associate degree: Occupational, Technical, or Vocational",
"Associate degree: Academic Program", "Bachelor's degree (ex. BA, AB, BS, BBS)",
"Master's degree (ex. MA, MS, MEng, MEd, MBA)", "Professional School degree (ex. MD, DDS, DVN, JD)",
"Doctoral degree (ex. PhD, EdD)", "Refused to answer", "Don't Know",
"unknown"), class = "factor"), event = structure(c(1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L,
3L, 3L, 3L, 3L, 5L, 5L, 5L, 5L, 5L, 7L, 9L, 9L, 9L, 9L, 9L, 9L,
9L, 9L, 11L, 11L), levels = c("Baseline", "0.5 Year", "1 Year",
"1.5 Year", "2 Year", "2.5 Year", "3 Year", "3.5 Year", "4 Year",
"4.5 Year", "5 Year", "5.5 Year", "6 Year", "Screener"), class = "factor"),
visit_type = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L), levels = c("on-site", "hybrid", "remote", "unknown"), class = "factor"),
n = c(2L, 13L, 5L, 9L, 15L, 18L, 26L, 25L, 192L, 27L, 485L,
224L, 183L, 1011L, 666L, 55L, 78L, 3L, 9L, 1L, 1L, 2L, 208L,
1L, 1L, 1L, 1L, 126L, 28L, 1L, 1L, 2L, 2L, 3L, 4L, 1L, 543L,
1L, 300L)), class = c("tbl_df", "tbl", "data.frame"), row.names = c(NA,
-39L))
I would assume that, generating a highcharter bar plot with:
library(highcharter) # v0.9.4
dta |>
hchart(type = "column", hcaes(x = "event", y = "n", group = "sociodemographic_var")) |>
hc_yAxis(title = list(text = "%"), max = 115, endOnTick = FALSE, stackLabels = list(enabled = TRUE)) |>
hc_xAxis(title = "") |>
hc_plotOptions(series = list(stacking = "percent"))
the xAxis would be ordered by levels(dta$event):
levels(dta$event)
[1] "Baseline" "0.5 Year" "1 Year" "1.5 Year" "2 Year" "2.5 Year" "3 Year" "3.5 Year" "4 Year" "4.5 Year" "5 Year" "5.5 Year"
[13] "6 Year" "Screener"
But the ordering is different and neither alphabetical nor based on the total number of values:
I am interested to understand why it's the case and how to set the order right.
You can add categories to your hc_xAxis to make an order like this:
library(highcharter)
dta |>
hchart(type = "column", hcaes(x = "event", y = "n", group = "sociodemographic_var")) |>
hc_yAxis(title = list(text = "%"), max = 115, endOnTick = FALSE, stackLabels = list(enabled = TRUE)) |>
hc_xAxis(title = "", categories = levels(dta$event)) |>
hc_plotOptions(series = list(stacking = "percent"))
Output:

Plotting labels of Points outside of Polygon with ggplot2/ggrepel

I am trying to do a map of my study areas using ggplot2 as I have seen some good outputs. I attached what I got from the following codes
The shapefile can be downloaded with this link.
library(ggplot2)
library(ggrepel)
points <- structure(list(city = structure(
c(
9L, 1L, 1L, 1L, 7L, 1L, 3L, 1L, 1L, 1L, 2L, 1L, 1L, 8L, 1L, 1L, 5L, 1L, 4L, 1L, 1L, 6L),
.Label = c("", "Adelaide", "Brisbane", "Canberra", "Darwin", "Hobart", "Melbourne", "Perth", "Sydney"),
class = "factor"),
site = structure(c(19L, 20L, 21L, 22L, 14L, 15L, 5L, 6L, 7L, 8L, 2L, 3L, 4L, 16L, 17L, 18L, 12L, 13L, 9L, 10L, 11L, 1L),
.Label = c("", "ADL1", "ADL2", "ADL3", "BNE1", "BNE2", "BNE3", "BNE4", "CBR1", "CBR2", "CBR3", "DRW1", "DRW2", "MEL1", "MEL2", "PER1", "PER2", "PER3", "SYD1",
"SYD2", "SYD3", "SYD4"), class = "factor"),
station = structure(c(8L, 5L, 12L, 16L, 10L, 3L, 22L, 18L, 17L, 20L, 2L, 14L, 11L, 4L, 7L, 19L, 15L, 21L, 6L, 9L, 13L, 1L),
.Label = c("", "Adelaide CBD", "Alphington", "Caversham", "Chullora", "Civic", "Duncraig", "Earlwood", "Florey", "Footscray", "Le Fevre 2", "Liverpool", "Monash", "Netley", "Palmerston", "Richmond", "Rocklea", "South Brisbane", "South Lake", "Springwood", "Winnellie", "Woolloongabba"), class = "factor"),
latitude = c(-33.9178, -33.8939, -33.9328, -33.6183, -37.8048, -37.7783, -27.4975, -27.4848, -27.5358, -27.6125, -34.9289, -34.9438, -34.7913, -31.9505, NA, NA, -12.50779, -12.4243233, -35.285307, -35.220606, -35.418302, -42.8821),
longitude = c(151.1347, 151.045, 150.9058, 150.7458, 144.8727, 145.0306, 153.035, 153.0321, 152.9934, 153.1356, 138.6011, 138.5492, 138.498, 115.8605, NA, NA, 130.94853, 130.8933502, 149.131579, 149.043539, 149.094018, 147.3272)),
.Names = c("city", "site", "station",
"latitude", "longitude"), class = "data.frame", row.names = c(NA, -22L))
AUS<-readRDS("gadm36_AUS_1_sp.rds")
ggplot() + geom_polygon(data = AUS, aes(x=long, y = lat, group = group, size=0.01),
fill = NA, color = "black") +
geom_point(data=points, aes(x=longitude, y=latitude), color ="blue", size=0.5) +
coord_fixed(1) +
geom_label_repel(data = points, aes(x=longitude, y=latitude, label=city),
box.padding = 1.2, point.padding = 1) +
theme_classic() + ylim(-60,0)+ xlim(100,180) + scale_size_identity()
Australia Map and my study areas:
Is there a way I can enlarge/expand the polygon so my points would be separated? Also can I direct all labels outside the polygon?

grid.arrange - make grid higher / extend

I would kindly like to ask for your help. I am trying to extend the graph grid below in order to fully display the three graphs. Everywhere I looked, I couldn't find any clues how to resize the actual grid, not each of the plots within them.
This is the code I am using:
p1 <- df %>%
filter(df$economic_area == "Poorer areas") %>%
group_by(cand_nm) %>%
summarise(sum = sum(contb_receipt_amt)) %>%
arrange(desc(sum)) %>%
ggplot(aes(x = reorder(cand_nm, -sum), y=sum)) + geom_bar(stat = "identity") +
theme(axis.text.x = element_text(angle = 55, hjust = 1)) +
scale_y_continuous(labels = comma) +
labs(x='Candidate',
y='Recieved donations in USD',
title='Donations per candidate from poorer areas')
p2 <- df %>%
filter(df$economic_area == "Middle income areas") %>%
group_by(cand_nm) %>%
summarise(sum = sum(contb_receipt_amt)) %>%
arrange(desc(sum)) %>%
ggplot(aes(x = reorder(cand_nm, -sum), y=sum)) + geom_bar(stat = "identity") +
theme(axis.text.x = element_text(angle = 55, hjust = 1)) +
scale_y_continuous(labels = comma) +
labs(x='Candidate',
y='Recieved donations in USD',
title='Donations per candidate from middle income areas')
p3 <- df %>%
filter(df$economic_area == "Upper class areas") %>%
group_by(cand_nm) %>%
summarise(sum = sum(contb_receipt_amt)) %>%
arrange(desc(sum)) %>%
ggplot(aes(x = reorder(cand_nm, -sum), y=sum)) + geom_bar(stat = "identity") +
theme(axis.text.x = element_text(angle = 55, hjust = 1)) +
scale_y_continuous(labels = comma) +
labs(x='Candidate',
y='Recieved donations in USD',
title='Donations per candidate from upper class areas')
grid.arrange(p1, p2, p3, nrow = 3, heights = c(10, 0.65, 0.65))
Thanks a lot for your help and best regards,
Trgovec
edit:
I have tried using facets as well, but it does not work.
p <- df %>%
group_by(cand_nm) %>%
summarise(sum = sum(contb_receipt_amt)) %>%
arrange(desc(sum)) %>%
ggplot(aes(x = reorder(cand_nm, -sum), y=sum)) + geom_bar(stat = "identity") +
theme(axis.text.x = element_text(angle = 55, hjust = 1)) +
scale_y_continuous(labels = comma) +
labs(x='Candidate',
y='Recieved donations in USD',
title='Recieved donations per candidate')
p + facet_grid(. ~ df$Median_household_income)
this is the error:
Error in `$<-.data.frame`(`*tmp*`, "PANEL", value = c(536L, 1279L, 380L, :
replacement has 618217 rows, data has 25
EDIT:
here is the reproducable dataset:
> dput(test)
structure(list(cand_nm = structure(c(4L, 4L, 20L, 23L, 1L, 20L,
19L, 5L, 23L, 1L, 12L, 3L, 19L, 2L, 5L, 8L, 16L, 6L, 12L, 3L,
4L, 15L, 24L, 22L, 11L, 2L, 17L, 6L, 9L, 17L, 11L, 19L, 8L, 16L,
22L, 20L, 13L, 24L, 5L, 23L, 15L, 25L, 9L, 14L, 9L, 10L, 21L,
13L, 1L, 10L, 18L, 12L, 21L, 14L, 2L, 7L, 17L, 16L, 25L, 22L,
3L, 8L, 15L, 18L, 6L, 24L, 7L, 11L), .Label = c("Bush, Jeb",
"Carson, Benjamin S.", "Christie, Christopher J.", "Clinton, Hillary Rodham",
"Cruz, Rafael Edward 'Ted'", "Fiorina, Carly", "Gilmore, James S III",
"Graham, Lindsey O.", "Huckabee, Mike", "Jindal, Bobby", "Johnson, Gary",
"Kasich, John R.", "Lessig, Lawrence", "McMullin, Evan", "O'Malley, Martin Joseph",
"Pataki, George E.", "Paul, Rand", "Perry, James R. (Rick)",
"Rubio, Marco", "Sanders, Bernard", "Santorum, Richard J.", "Stein, Jill",
"Trump, Donald J.", "Walker, Scott", "Webb, James Henry Jr."), class = "factor"),
economic_area = structure(c(2L, 3L, 2L, 2L, 2L, 3L, 2L, 2L,
3L, 3L, 2L, 2L, 3L, 2L, 3L, 2L, 2L, 2L, 3L, 3L, 1L, 2L, 2L,
2L, 2L, 3L, 2L, 3L, 2L, 3L, 3L, 1L, 3L, 3L, 3L, 1L, 2L, 3L,
1L, 1L, 3L, 2L, 3L, 2L, 1L, 2L, 2L, 3L, 1L, 3L, 2L, 1L, 3L,
3L, 1L, 3L, 1L, 1L, 3L, 1L, 1L, 1L, 1L, 3L, 1L, 1L, 2L, 1L
), .Label = c("Poorer areas", "Middle income areas", "Upper class areas"
), class = "factor"), sum = c(125925526.85, 16410009.07,
5622760.67, 4233067.76, 2551429, 1985456.25, 1626777.31,
1154448.33, 1104488.41, 860788, 621133.75, 587637, 566709.69,
436575.16, 358550.75, 271350.07, 227328.63, 218724.23, 211130.5,
211075, 197447.84, 195618, 192773, 191260.1, 167872.43, 161952.1,
141996.17, 121297.5, 92806, 80349.55, 70725.29, 66755, 63672,
62400, 58971, 48382.4, 48291.56, 44000, 43426.5, 38671.22,
37890, 29900, 28964, 21753, 20750, 19626.42, 16655.1, 15980.75,
15021, 12550, 12250, 12150, 9900, 8434.5, 6092, 5800, 5450,
4425.66, 4050, 2936, 2700, 2700, 2700, 1750, 1000, 1000,
600, 575)), row.names = c(NA, -68L), class = c("grouped_df",
"tbl_df", "tbl", "data.frame"), vars = "cand_nm", drop = TRUE, .Names = c("cand_nm",
"economic_area", "sum"), indices = list(c(4L, 9L, 48L), c(13L,
25L, 54L), c(11L, 19L, 60L), c(0L, 1L, 20L), c(7L, 14L, 38L),
c(17L, 27L, 64L), c(55L, 66L), c(15L, 32L, 61L), c(28L, 42L,
44L), c(45L, 49L), c(24L, 30L, 67L), c(10L, 18L, 51L), c(36L,
47L), c(43L, 53L), c(21L, 40L, 62L), c(16L, 33L, 57L), c(26L,
29L, 56L), c(50L, 63L), c(6L, 12L, 31L), c(2L, 5L, 35L),
c(46L, 52L), c(23L, 34L, 59L), c(3L, 8L, 39L), c(22L, 37L,
65L), c(41L, 58L)), group_sizes = c(3L, 3L, 3L, 3L, 3L, 3L,
2L, 3L, 3L, 2L, 3L, 3L, 2L, 2L, 3L, 3L, 3L, 2L, 3L, 3L, 2L, 3L,
3L, 3L, 2L), biggest_group_size = 3L, labels = structure(list(
cand_nm = structure(1:25, .Label = c("Bush, Jeb", "Carson, Benjamin S.",
"Christie, Christopher J.", "Clinton, Hillary Rodham", "Cruz, Rafael Edward 'Ted'",
"Fiorina, Carly", "Gilmore, James S III", "Graham, Lindsey O.",
"Huckabee, Mike", "Jindal, Bobby", "Johnson, Gary", "Kasich, John R.",
"Lessig, Lawrence", "McMullin, Evan", "O'Malley, Martin Joseph",
"Pataki, George E.", "Paul, Rand", "Perry, James R. (Rick)",
"Rubio, Marco", "Sanders, Bernard", "Santorum, Richard J.",
"Stein, Jill", "Trump, Donald J.", "Walker, Scott", "Webb, James Henry Jr."
), class = "factor")), row.names = c(NA, -25L), class = "data.frame", vars = "cand_nm", drop = TRUE, .Names = "cand_nm"))
I would basically like to combine these three graphs into one extended graph grid / page:
1)
2)
3)

Expand plot region in windroses using ggplot 2 and polar coordination system

I am looking for a solution for the following problem:
Currently I am producing a wind rose plot with ggplot2 following the script provided by Andy Clifton over here.
This works perfectly and I am very thankful for the script provided. However I am having one problem. The labels for the X-Axis get truncated by the edge of the plot, especially when plotting in a facet.
Is there a way to expand the plot so that the text is fully shown?
(an example picture can be found at the link above)
To practice with a windrose, using the data frame at the end, I created the following plot, which has no issues of x-axis labels being truncated. It admittedly doesn't concern wind speeds or a 24-hour framework, as it is intended for amounts paid to two kinds of vendors, but the plot and the data may help others respond more easily.
> dput(lfvendrose)
structure(list(Time = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12), Payee = structure(c(1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("Firm", "Vendor"), class = "factor"),
Data1 = structure(c(12L, 10L, 8L, 13L, 7L, 9L, 14L, 3L, 5L,
17L, 6L, 11L, 2L, 15L, 18L, 2L, 4L, 19L, 1L, 16L, 18L, 2L,
15L, 18L), .Label = c("0, 1", "0, 13", "0, 15", "0, 2", "0, 20",
"0, 34", "0, 39", "0, 40", "0, 41", "0, 45", "0, 48", "0, 50",
"0, 64", "0, 68", "0, 9", "0, 90", "0, 94", "0,11", "0,16"
), class = "factor"), Month = structure(c(5L, 4L, 8L, 1L,
9L, 7L, 6L, 2L, 12L, 11L, 10L, 3L, 5L, 4L, 8L, 1L, 9L, 7L,
6L, 2L, 12L, 11L, 10L, 3L), .Label = c("Apr", "Aug", "Dec",
"Feb", "Jan", "Jul", "Jun", "Mar", "May", "Nov", "Oct", "Sep"
), class = "factor"), Month.1 = structure(c(5L, 4L, 8L, 1L,
9L, 7L, 6L, 2L, 12L, 11L, 10L, 3L, 5L, 4L, 8L, 1L, 9L, 7L,
6L, 2L, 12L, 11L, 10L, 3L), .Label = c("Apr", "Aug", "Dec",
"Feb", "Jan", "Jul", "Jun", "Mar", "May", "Nov", "Oct", "Sep"
), class = "factor"), Data2 = structure(c(11L, 10L, 6L, 12L,
8L, 4L, 13L, 3L, 7L, 15L, 9L, 5L, 2L, 14L, 16L, 1L, 11L,
10L, 6L, 12L, 8L, 4L, 13L, 3L), .Label = c("0, 13,1", "0, 13,50",
"0, 15, 30", "0, 40, 100", "0, 40,1", "0, 40,3", "0, 40,5",
"0, 45, 5", "0, 45,15", "0, 45,2", "0, 50,1", "0, 64, 4",
"0, 64,200", "0, 9,150", "0, 94,10", "0,11, 400"), class = "factor")), .Names = c("Time",
"Payee", "Data1", "Month", "Month.1", "Data2"), class = "data.frame", row.names = c(NA,
-24L))

Resources