Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6795847
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:23:45+00:00 2026-05-26T18:23:45+00:00

I am using ggplot2 to plot a pointrange() plot, and both the x and

  • 0

I am using ggplot2 to plot a pointrange() plot, and both the x and y labels are oddly separate from the end of their respective ticks. This doesn’t happen with all of the plots in this particular script, only a few, including this one (which is based on a subset of the available data, but shows the problem):

Example of odd plotting behavior

As you can see, the y axis labels are offset substantially to the left, and the x axis labels are offset substantially below the ticks, to the extent that they are overplotted above the axis label.

The only modification I have made to theme_bw() prior to producing this plot is to set theme_set(theme_bw(base_size = 8)) — no changes have been deliberately made to the text justification prior to the plot code.

Here is a dput() of the subset plotted below:

TestData:
structure(list(State = c("AL", "AZ", "CA", "CO", "CT", "DC", 
"DE", "FL", "GA", "IL"), Year = c(2008L, 2008L, 2008L, 2008L, 
2008L, 2008L, 2008L, 2008L, 2008L, 2008L), N = c(22L, 42L, 286L, 
99L, 30L, 14L, 20L, 173L, 78L, 29L), Polarization = c(0.352923743188869, 
0.505918664112271, 0.445768659699068, 0.555930347461176, -0.0133878043740006, 
-0.380342319255035, -0.450998867087007, 0.385507917713463, 0.368070478718073, 
0.23368733390603), PolarizationSE = c(0.16021790292877, 0.0650610761652209, 
0.0100695976668952, 0.0270310803233059, 0.127526745827604, 0.296328985544823, 
0.179653490097689, 0.0180113004747975, 0.0372516250664796, 0.112905812606479
), IDPol = c(0.198743353462518, 0.0416441096132583, 0.0551808637190376, 
0.110549247724351, 0.302497569072991, -0.0343523165297017, -0.00367975496702999, 
0.0520660142625065, 0.0762126127715774, 0.0936515057040723), 
IDPolSE = c(0.102763798140243, 0.0523842634480865, 0.00789292373693809, 
0.023425554880421, 0.0918856966184178, 0.184867986813743, 
0.122339223641891, 0.0137386656250425, 0.0285951418531372, 
0.0896433805255375), Estimate = c(0.00932965761458826, -0.000412018017715892, 
0.00315002626133457, 0.00823125148777124, 0.000741919819714724, 
-0.0211994171332907, -0.0218353390160545, 0.00290805283382581, 
0.00406489584624635, 0.00604261698709428), Std..Error = c(0.00398420082222495, 
0.00483343236746232, 0.00186579338568264, 0.0032167092866312, 
0.00379995092553099, 0.0128981988697743, 0.0122846784163747, 
0.00220581166165486, 0.00335683359383524, 0.00240425995025825
), StateN = structure(c(13L, 25L, 18L, 27L, 4L, 2L, 1L, 15L, 
14L, 7L), .Label = c("DE (20)", "DC (14)", "WA (23)", "CT (30)", 
"TX (365)", "NY (123)", "IL (29)", "PA (36)", "MI (114)", 
"KS (28)", "OK (36)", "NJ (23)", "AL (22)", "GA (78)", "FL (173)", 
"SC (69)", "MN (25)", "CA (286)", "OH (85)", "VA (34)", "IN (55)", 
"OR (27)", "WI (22)", "NM (64)", "AZ (42)", "TN (77)", "CO (99)", 
"LA (83)", "MA (22)", "NC (65)", "MS (63)"), class = "factor")), .Names = c("State", 
"Year", "N", "Polarization", "PolarizationSE", "IDPol", "IDPolSE", 
"Estimate", "Std..Error", "StateN"), row.names = c(1401L, 1403L, 
1404L, 1405L, 1406L, 1407L, 1408L, 1409L, 1410L, 1414L), class = "data.frame")

And here is the code used to produce the plot:

TestData$StateN <- paste(TestData$State, " (", TestData$N, ")", sep = "")
TestData$StateN <- factor(TestData$StateN, levels = TestData$StateN[order(TestData$Polarization)])

ZP17Test <- ggplot(TestData,
 aes(x = StateN, y = Polarization,
 ymin = Polarization - 1.96 * PolarizationSE, ymax = Polarization + 1.96 * PolarizationSE))
ZP17Test <- ZP17Test + geom_hline(yintercept = 0, colour = I(MyPalette(5)[3]), alpha = I(7/12), size = I(1/3))
ZP17Test <- ZP17Test + geom_pointrange(size = I(1/3))
ZP17Test <- ZP17Test + scale_x_discrete("State (Number of Respondents)")
ZP17Test <- ZP17Test + opts(title = "State Polarization Levels in 2008",
 axis.text.x = theme_text(angle=45, hjust=1, size = 7))
print(ZP17Test)
ggsave(plot = ZP17Test, "Analysis/Stack_Overflow.png", h = 4, w = 6)

Thanks in advance for any help you can offer.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T18:23:45+00:00Added an answer on May 26, 2026 at 6:23 pm

    Angled axis text labels always messes with my head. What you wanted was this:

    axis.text.x = theme_text(hjust = 1,vjust = 1,angle=45, size = 7)
    

    The order you specify them in makes a difference, in my experience. I always have to fiddle with it until I get it just right. Smarter folks can probably remember the system to it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using ggplot2 to plot a figure that contains nine facets. Each facet
I'm trying to plot heatmap in ggplot2 using csv data following casbon's solution in
From the documentation for ggplot2's geom_tile() function, we have the following simple plot: #
I wish to recreate this graph: (from here ) Using R base graphics. I
Is it possible to plot a matrix of scatter plots with ggplot2 , using
In my work, I frequently display scatterplots using text labels. That's meant a plot()
I am using ggplot2 to plot simple line charts of time series data. One
I'm using ggplot2 and attempting to create an empty plot with some basic dimensions,
I'm using ggplot2 to make some bullseye charts in R. They look delightful, and
I'm plotting a group of curves, using facet in ggplot2. I'd like to have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.