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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:23:33+00:00 2026-05-26T03:23:33+00:00

I am trying to plot randomization layout in R/ graphics. Trt <- c(paste (Trt#,

  • 0

I am trying to plot randomization layout in R/ graphics.

Trt <- c(paste ("Trt#", 1:10, sep = ""))
    mydes <- data.frame (block1= sample(Trt), block2 = sample(Trt), block3= sample(Trt), block4= sample( Trt), block5= sample(Trt))
    plot(c(0, NCOL(mydes)), c(0, NROW(mydes)), type= "n", xlab="blocks", ylab = "range")
    grid(lty = 2, col = 1)

    mydes 
       block1 block2 block3 block4 block5
    1  Trt#10  Trt#5  Trt#4  Trt#6  Trt#8
    2   Trt#6  Trt#8  Trt#9  Trt#2  Trt#3
    3   Trt#3  Trt#6  Trt#5 Trt#10  Trt#9
    4   Trt#9  Trt#4  Trt#1  Trt#5  Trt#2
    5   Trt#5  Trt#9  Trt#7  Trt#3  Trt#5
    6   Trt#7  Trt#3  Trt#3  Trt#7  Trt#7
    7   Trt#8 Trt#10  Trt#8  Trt#4  Trt#4
    8   Trt#1  Trt#7 Trt#10  Trt#9  Trt#1
    9   Trt#4  Trt#1  Trt#2  Trt#1 Trt#10
    10  Trt#2  Trt#2  Trt#6  Trt#8  Trt#6

I want to add the text in middle of each grid rectangle. I know I can do it painfully by adding text and specifying coordinates one by one. But I want a generalized solution with some short of loop, that can be applied to any other dimensions as well.

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-05-26T03:23:33+00:00Added an answer on May 26, 2026 at 3:23 am

    Here is a way of doing it in ggplot:

    library(ggplot2)
    
    blocks <- expand.grid(
      x = 1:ncol(mydes),
      y = 1:nrow(mydes)
    )
    
    blocks$label <- unname(rapply(mydes, as.character))
    
    ggplot(blocks) + 
      geom_rect(aes(xmin=x-0.4, xmax=x+0.4, ymin=y-0.4, ymax=y+0.4), fill="cyan") +
      geom_text(aes(label=label, x=x, y=y)) +
      xlab("Blocks") + ylab("Treatments")
    

    enter image description here

    Since you want to plot this, rather than just printing a table, you may as well use a colour scale to map treatments with the same value:

    ggplot(blocks) + 
      geom_rect(aes(xmin=x-0.4, xmax=x+0.4, ymin=y-0.4, ymax=y+0.4, fill=label)) +
      geom_text(aes(label=label, x=x, y=y)) +
      xlab("Blocks") + ylab("Treatments") +
      scale_fill_hue("Treatment", h=c(90, 150))
    

    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 am trying to plot side by side the following datasets dataset1=data.frame(obs=runif(20,min=1,max=10)) dataset2=data.frame(obs=runif(20,min=1,max=20)) dataset3=data.frame(obs=runif(20,min=5,max=10))
I am trying plot data sets consisting of 3 coordinates: X-coordinate, x-coordinate and the
I have the following data set that I am trying to plot with ggplot2,
I'm trying to annotate a polar plot with data tips labelled with 'R:...,Theta:...' where
I have a plot (sample code pasted below) that I am trying to add
I'm trying to plot heatmap in ggplot2 using csv data following casbon's solution in
I'm trying to plot two sets of data wrt to time on the same
I'm trying to plot out GPS data that is given to me in Hour
I am trying to plot a bunch of data points (many thousands) in Python
I am trying to plot two data series in an MSChart. I am using

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.