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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T16:52:30+00:00 2026-05-13T16:52:30+00:00

I have a two vectors of numbers of equal length. How do I plot

  • 0

I have a two vectors of numbers of equal length. How do I plot the first vector while using the corresponding element in the second vector as the printing character? (Background: I sorted the first column and the second column holds the original indices. I want to use the indices as the printable character so that I can see which data points are outliers, since each number represents one run of data).

 > x
$x
 [1]   25   29   30   34   38  572  700  733  870  879  899  934  982 1054 1135 1258
[17] 1315 1491 1685 1700 2069 2131 2284 3498 3506 4467 4656 5633 6642 8348

$ix
 [1] 23  3 18 30 13  8  4 14 11 17 12 29  9 15 19 16  7  1 20  2  6 28 21 10  5 22 24 26
[29] 25 27

First vector is x$x, second vector is x$ix (results of calling sort with index.return = TRUE)

I’ve tried plot(x$x, pch=str(x$ix)) but that treats x$ix numerically. If this were Python I would do something like strings = [str(x) for x in x$ix]. but this is R and I’ve forgotten most of what I used to know.

I found that you can do as.character(x$ix) in order to get the strings,

> as.character(x$ix)
 [1] "23" "3"  "18" "30" "13" "8"  "4"  "14" "11" "17" "12" "29" "9"  "15" "19" "16"
[17] "7"  "1"  "20" "2"  "6"  "28" "21" "10" "5"  "22" "24" "26" "25" "27"

and I can use this as the input to pch. But only the first character is used (and according to the docs, that’s normal).

I know there’s a way to do this; I did it in college. But I can’t for the life of me remember how I did it.

Chart without labels:
alt text

Chart with labels, but incorrect:
alt text

  • 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-13T16:52:30+00:00Added an answer on May 13, 2026 at 4:52 pm

    This should work:

    x = 1:4
    y = x
    plot(x, y, ann=F, axis=F, col="blue", pch=16)
    text(x, y, labels=c("1st", "2nd", "3rd", "4th"), col="red", pos=c(3,4,4,1), offset=0.6)
    

    Just convert your non-data vector (the one containing the labels) to a character vector:
    labels = as.character(label_vector)

    and then substitute this for the third argument in line 4 above.

    The ‘Text’ function is fairly versatile because of the various arguments you can pass in–e.g., (as in the example above) you can set the text to a different color than your data points using “col”; You can also specify the position (relative to the data point annotated by a given text label) for each text label separately. That’s often useful to keep text labels from, for instance, overlapping one of the axes, which is what happened the first time i ran this example without setting ‘pos’. So by setting ‘pos’ (as c(3, 4, 4, 1)) i set the position of the text labels as “above”, “right”, “right”, and “below”–moving the first data point up so it doesn’t hit the bottom x-axis, and moving the fourth one down so it doesn’t hit the top x-axis. Additionally, using ‘offset’ (which has a default value of 0.5) you can specify the magnitude of the position adjustment.

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

Sidebar

Related Questions

I have two vectors, and I would like to fill the first one with
I have two large vectors, I am trying to do some sort of element
Lets say - I have the two vectors: a numbers=[14 14 2 25 25
I am trying to accomplish two things. First if I have a vector 1:5
I have two connected vectors of arrays of numbers. What is the fastest way
I have two vectors of floats and i want them to become one vector
I have a two vectors of spatial data (each about 2000 elements in length).
I am using Matlab, and I have a 1x200 vector of numbers. I need
I am trying to multiply two vectors together where each element of one vector
I have two endpoints (xa,ya) and (xb,yb) of two vectors, respectively a and b,

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.