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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:41:04+00:00 2026-06-14T19:41:04+00:00

For the iris data, we get the scatter plot using the pairs() function as

  • 0

For the iris data, we get the scatter plot using the pairs() function as below:

pairs(iris[1:4], 
      main = "Edgar Anderson's Iris Data", 
      lower.panel=panel.pearson, 
      pch = 21, 
      bg = c("red", "green3", "blue")[unclass(iris$Species)])

With the function panel.pearson defined as follows:

panel.pearson <- function(x, y, ...) {
horizontal <- (par("usr")[1] + par("usr")[2]) / 2;
vertical <- (par("usr")[3] + par("usr")[4]) / 2;
text(horizontal, vertical, format(abs(cor(x,y)), digits=2)) }

I needed to convert the lower panel to correlation matrix and remove the labels from the diagonal and put them along the right and bottom axes. I tried the following:

pairs(iris[1:4], 
      main = "Edgar Anderson's Iris Data", 
      labels=NULL, 
      lower.panel=panel.pearson, 
      xaxt='n', 
      yaxt='n', 
      pch = 21, 
      bg = c("red", "green3", "blue")[unclass(iris$Species)])

This gives me what I need. Except that I do not understand how to get the labels on the bottom and right axes (the variable labels, I mean, Sepal.Length, Sepal.Width etc..). Any help is tremendously appreciated. 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-14T19:41:05+00:00Added an answer on June 14, 2026 at 7:41 pm

    Is this what you had in mind?

    # Horizontal axis
    text(seq(.2, 2, length.out=4), 0,
         c("Sepal Length","Sepal Width","Petal Length","Petal Width"),
         xpd=TRUE, adj=c(0,.5), cex=.9)
    
    # Vertical axis
    text(0, seq(0.35, 2.05, length.out=4),
         rev(c("Sepal Length","Sepal Width","Petal Length","Petal Width")),
         xpd=TRUE, adj=c(0.5, 0), 
         srt=90,  # rotates text to be parallel to axis
         cex=.9)
    

    I positioned the labels by trial and error. There’s probably a better way, but at least this gets the labels in (nearly) the right place.

    Update: A new SO question gave me an idea for a slightly better way to position the axis labels. As the linked answer points out, you can get the current coordinates of the plot area with par('usr'). So here’s an update to the code, based on that:

    x.coords = par('usr')[1:2]
    y.coords = par('usr')[3:4]
    
    # Offset is estimated distance between edge of plot area and beginning of actual plot
    x.offset = 0.03 * (x.coords[2] - x.coords[1])  
    xrng =  (x.coords[2] - x.coords[1]) - 2*x.offset
    x.width = xrng/4  
    
    y.offset = 0.028 * (y.coords[2] - y.coords[1])
    yrng =  (y.coords[2] - y.coords[1]) - 2*y.offset
    y.width = yrng/4  
    
    # seq function below calculates the location of the midpoint of each panel
    
    # x-axis labels
    text(seq(x.coords[1] + x.offset + 0.5*x.width, x.coords[2] - x.offset - 0.5*x.width,
             length.out=4), 0,
         c("Sepal Length","Sepal Width","Petal Length","Petal Width"),
         xpd=TRUE,adj=c(.5,.5), cex=.9)
    
    # y-axis labels
    text(0, seq(y.coords[1] + y.offset + 0.5*y.width, y.coords[2] - 3*y.offset - 0.5*y.width, 
         length.out=4),
         rev(c("Sepal Length","Sepal Width","Petal Length","Petal Width")),
         xpd=TRUE, adj=c(0.5, 0.5), 
         srt=90,  # rotates text to be parallel to axis
         cex=.9)
    

    It’s still not ideal, because the size of the offset is determined by trial and error. If someone knows how R determines the size of the offset between the boundary of the plot area and where the actual plot begins, then the offset can be determined programmatically also.

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

Sidebar

Related Questions

I plot Iris data with ggplot2 . It seems ggplot2 will standardized the data
I currently use the following function to list the classes of a data.frame: sapply(names(iris),function(x)
Suppose that I performed clustering of iris.data using SOM Toolbox in Matlab. After clustering,
Background: I am trying to animate a rotating 3D scatter plot using R's lattice::cloud()
The following block of code fails, for no reason I can discern. library(caret) data(iris)
I am using by to apply a function to a range columns of a
Very simple concept: data(iris) d1=as.matrix(iris) d2=as.array(iris) Error in <code>dimnames<-.data.framecode>(<code>*tmp*code>, value = list(n)) :invalid 'dimnames'
I'm using the neuralnet package in R, however am having problems saving the plot
When I run the following codes in R, library(mclust) data(iris) mc <- Mclust(iris[,1:4], 3)
Data set: Iris How to compute the confusion matrix on the data set for

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.