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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:38:51+00:00 2026-05-27T20:38:51+00:00

I am looking for a way to plot a matrix of type character: m=matrix(data=c(A,A,B,B,B,C,C,B),nrow=4,ncol=2)

  • 0

I am looking for a way to plot a matrix of type character:

m=matrix(data=c("A","A","B","B","B","C","C","B"),nrow=4,ncol=2)
> m
     [,1] [,2]
[1,] "A"  "B" 
[2,] "A"  "C" 
[3,] "B"  "C" 
[4,] "B"  "B" 

with a defined set of colours

A="Yellow"
B="Blue"
C="Green"

Should I pass from matrix to ascii and use image() from sp package?

I am looking fro something like this:

enter image description 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-05-27T20:38:51+00:00Added an answer on May 27, 2026 at 8:38 pm

    It rather depends on what you meant by “plot a matrix”:

     m2 <- m
     m2[] <- c("yellow", "blue","green")[match(m, c("A","B","C"))]
     m2
    #------------
     [,1]     [,2]   
    [1,] "yellow" "blue" 
    [2,] "yellow" "green"
    [3,] "blue"   "green"
    [4,] "blue"   "blue" 
    #------------
    plot(row(m2), col(m2), col=m2, pch=18, cex=4)
    

    This plots solid diamonds of the specified color at the matrix locations determined by the row and columns of matrix m. Another way with image:

    m2[] <- match(m, c("A","B","C"))
    mode(m2) <- "numeric"
    m2
    image(1:nrow(m2), 1:ncol(m2), m2, col=c("yellow", "blue","green"))
    

    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 looking for some way in to convert a scatter plot (X vs Y,
I am looking for a simple way to visualize some of my data in
I'm looking for a way to plot a bar chart containing two different series,
I am currently looking at a way of visualising data and a part of
I'm looking for a fast and easy way to plot arbitrarily colored pixels in
I'm looking for way to PHP to detect if a script was run from
I'm looking a way to enable IP logging with log4net in ASP.NET. I found
I'm looking for way to write Javascript programs / scripts on desktop, not inside
I'm looking a way to build conditional assignments in bash: In Java it looks
I am using codeigniter and looking a way to enable directly editting of doc

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.