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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T16:24:52+00:00 2026-06-05T16:24:52+00:00

This question is related to the one I asked here . I’m trying to

  • 0

This question is related to the one I asked here. I’m trying to color individual points in a scatterplot with a color specified in a column of the dataframe. The data is from a tab delimited file and looks like this:

> dput(ztestHSV)
structure(list(y = c(0, -1, -1, -2), x = c(0, 2, 0, -2), group = c("m", 
"m", "m", "s"), colorHSV = c("0.02,0.83,0.89", "0.59,0.59,0.85", 
"0.25,0.45,0.8", "0.55,0.41,0.8"), colorText = c("red", "blue", 
"green", "turquoise")), .Names = c("y", "x", "group", "colorHSV", 
"colorText"), class = "data.frame", row.names = c(NA, -4L))

i.e.

   y  x group  colorHSV       colorText
1  0  0     m  0.02,0.83,0.89       red
2 -1  2     m  0.59,0.59,0.85      blue
3 -1  0     m  0.25,0.45,0.8      green
4 -2 -2     s  0.55,0.41,0.8  turquoise

The following code works well for the predefined set of colors available in R:

ztestHSV=read.table(file="testHSV.txt",sep="\t",header=TRUE,
                    colClasses=c("numeric","numeric","character","character","character"))

plot(ztestHSV[ztestHSV$group=='m',]$x,ztestHSV[ztestHSV$group=='m',]$y,type='n')
points(ztestHSV[ztestHSV$group=='m',]$x,ztestHSV[ztestHSV$group=='m',]$y,
       pch=23,cex=1.5,
       bg=ztestHSV[ztestHSV$group=='m',]$colorText
)

What I would really like to do is use hsv() to specify the colors. But I can’t figure out the right bg command to make it work. I’ve tried several things and listed them below with the associated result.

1

bg=hsv(as.numeric(ztestHSV$colorHSV))

Error in hsv(as.numeric(ztestHSV$colorHSV)) : 
bad hsv to rgb color conversion
In addition: Warning message:
In hsv(as.numeric(ztestHSV$colorHSV)) : NAs introduced by coercion

2

bg=hsv(as.numeric(strsplit(ztestHSV$colorHSV,",")))

Error in hsv(as.numeric(strsplit(ztestHSV$colorHSV, ","))) : 
(list) object cannot be coerced to type 'double'

3

bg=hsv(unlist(strsplit(ztestHSV$colorHSV,",")))

Above runs but uses the wrong background colors

4

bg=hsv(as.numeric(unlist(strsplit(ztestHSV$colorHSV,","))))

Above doesn’t generate an error but doesn’t fill background colors

It seems like this is a problem with converting the character string of colorHSV to something that hsv() can use, but I don’t know how to do it. Any help would be great.

  • 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-05T16:24:54+00:00Added an answer on June 5, 2026 at 4:24 pm

    It helps if you provide an easily reproducible example by using something like dput() to show the data you are using:

    > dput(ztestHSV)
    structure(list(y = c(0L, -1L, -1L, -2L), x = c(0L, 2L, 0L, -2L
    ), group = structure(c(1L, 1L, 1L, 2L), .Label = c("m", "s"), class = "factor"), 
        colorHSV = c("0.02,0.83,0.89", "0.59,0.59,0.85", "0.25,0.45,0.8", 
        "0.55,0.41,0.8"), colorText = structure(c(3L, 1L, 2L, 4L), .Label = c("blue", 
        "green", "red", "turquoise"), class = "factor")), .Names = c("y", 
    "x", "group", "colorHSV", "colorText"), row.names = c(NA, -4L
    ), class = "data.frame")
    

    You can convert the vector of character strings into a list of numerics, and then use do.call() to call hsv() on each one, like this:

    > bg <- sapply(strsplit(ztestHSV$colorHSV, ","), function(x) do.call(hsv, as.list(as.numeric(x))))
    > dput(bg)
    c("#E33D27", "#5994D9", "#9ECC70", "#78B3CC")
    > plot(1:4, pch = 21, cex = 20, bg = bg)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This question is related somewhat to the one i asked HERE . Now, i
This question is related to one I asked previously, see here . As a
This question is similar to the one i asked here . But its related
I have a question related to this one : I'm trying to attach an
This is a related question to one I posted earlier... I'm trying to sum
This question is related to one I asked the other day which I got
This question is maybe related to the question i asked here: Jquery ajax request
This is a question related to another one I asked that was specific to
I asked a question related to this one previously but I need to know
This question is related to my earlier question, asked here: How do I get

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.