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 8569315
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T18:18:23+00:00 2026-06-11T18:18:23+00:00

I am using R with cygwin and am trying to plot some basic graphics.

  • 0

I am using R with cygwin and am trying to plot some basic graphics. Here is a simple example from one of Paul Murrell’s papers:

library(grid)
x <- rnorm(50)
y <- x + rnorm(50, 1, 2)
rx <- range(x)
dx <- diff(rx)
ry <- range(y)
dy <- diff(ry)
max <- max(rx, ry)
min <- min(rx, ry)
r <- c(min(rx, ry), max(rx, ry))
d <- diff(r)
scale <- r + c(-1, 1) * d * 0.05
extscale <- c(min(scale), max(scale) + diff(scale) * 1/3)
lay <- grid.layout(2, 2, 
                   widths = unit(c(3, 1), "inches"), 
                   heights = unit(c(1, 3), "inches"))
vp1 <- viewport(w = unit(4, "inches"), h = unit(4, "inches"), 
                layout = lay, xscale = extscale, yscale = extscale)
grid.newpage()
pushViewport(vp1)
grid.rect()
grid.xaxis()
grid.text("Test", y = unit(-3, "lines"))
grid.yaxis()
grid.text("Retest", x = unit(-3, "lines"), rot = 90)
vp2 <- viewport(layout.pos.row = 2, layout.pos.col = 1, 
                xscale = scale, yscale = scale)
pushViewport(vp2)
grid.lines()
grid.points(x, y, gp = gpar(col = "blue"))

This plots fine. If however I add the following line to the program:

grid.lines(x, y, gp = gpar(col = "red"))

The lines are all over the place. I had expected that lines would connect the points in order. I have had a similar problem with some code I wrote but there the lines plot fine but the points do not.

Would appreciate any help. Thanks.

  • 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-11T18:18:25+00:00Added an answer on June 11, 2026 at 6:18 pm

    For some reason, grid.points() and grid.lines() have different “default units”. (These are the units — "native" and "npc" respectively — that are used when you pass the functions a numeric vector without any associated units.)

    args(grid.lines)
    # function (x = unit(c(0, 1), "npc"), y = unit(c(0, 1), "npc"), 
    #     default.units = "npc", arrow = NULL, name = NULL, gp = gpar(), 
    #     draw = TRUE, vp = NULL)     
    args(grid.points)
    # function (x = stats::runif(10), y = stats::runif(10), pch = 1, 
    #     size = unit(1, "char"), default.units = "native", name = NULL, 
    #     gp = gpar(), draw = TRUE, vp = NULL) 
    

    The quick solution is to explicitly set the default units for grid.lines() to match those used by grid.points():

    grid.lines(x, y, gp = gpar(col = "red"), default.units = "native")
    

    enter image description here

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

Sidebar

Related Questions

I'm trying to compile a relatively simple c++ program using cygwin and g++. I
I am trying to execute unix command using SSH from cygwin. My set of
I am trying to port a C++ program from Linux to Windows using cygwin.
I'm trying to invoke a native Windows command from Cygwin using run , but
noob here, I'm trying to transfer a file using rsync from windows to linux.
Trying to use make from cygwin using g++ I was getting Access Denied error
I am trying to do ssh connection using cygwin. I have followed instructions given
I'm trying to copy files to C:\Windows\System32 using cygwin bash. When I copy files
I am trying to set up an automated build system on Windows using Cygwin.
I have been trying to setup a environment variable in Cygwin using the command

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.