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

  • SEARCH
  • Home
  • 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 8819665
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T05:25:05+00:00 2026-06-14T05:25:05+00:00

library(maptools) data(wrld_simpl) plot(wrld_simpl) box() This gives me a world map and shows the plentiful

  • 0
library(maptools)
data(wrld_simpl)
plot(wrld_simpl)
box()

This gives me a world map and shows the plentiful white space top and bottom of the map. I would like this space to be gone as I need to print many (~60) maps. I am using knitr for the report in which the maps will be embedded. E.g.

Here is some text.
<<chunk.maps, eval = TRUE>>=
library(maptools)
plot(wrld_simpl)
box()
@
And some more text.

But I don’t think this is a knitr question. So:

  1. How can I get rid of the white space?
  2. How can I make sure that the map fills my page from left to right?

I have tried mai, mar, par, but no such luck! I am guessing out.width for the chunk option will give the result for my question 2, but since I am so badly stuck on question 1 I find it hard to tell.

Thank you very much! There is so much to learn out here!

  • 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-06-14T05:25:07+00:00Added an answer on June 14, 2026 at 5:25 am

    I use ggplot2 for these kinds of maps:

    require(ggplot2); theme_set(theme_bw())
    wrld_simpl_df = fortify(wrld_simpl)
    ggplot(wrld_simpl_df, aes(x = long, y = lat, group = group)) + 
       geom_path() + coord_equal()
    

    enter image description here

    This also includes the whitespace you where complaining about. The problem is that the aspect ratio between the x- and y-axis is fixed. So if you choose a square graphics device, that will leave white borders above and below. The solution is to make your graphics device have roughly the same proportions as your plot. Use fig.width and fig.height to do this. See this link for more info. As an illustration, when saving the plot above with the correct proportions:

    ggsave("/tmp/plt.png", width = 16, height = 9)
    

    enter image description here

    the problem is no longer present.

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

Sidebar

Related Questions

I'm using R to plot map files. setwd(c:\\apa\\) # Load libraries library(maptools) library(RColorBrewer) library(classInt)
library(ggplot2) This code produces a nice looking plot: qplot(cty, hwy, data = mpg, colour
library(ggplot2) my_title = This is a really long title of a plot that I
A library I'm writing has a class implementing a two dimensional map and also
Is there an R library/function that would implement INTELLIGENT label placement in R plot?
Which library/project is currently usable for creating Facebook applications? This is a followup to
library(ggplot2) df <- data.frame(x=1:10, y=rnorm(10)) p1 <- ggplot(df, aes(x,y)) + geom_point() plist <- list(p1,p1,p1,p1,p1)
Which library or component can do this in a easy way and not too
New Library: XParsec This question has lead to a stream-and-type-independent, non-linear, extensible parsec implementation
library(MASS) example(lda) plot(z) How can I access all the points in z? I want

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.