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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T02:58:59+00:00 2026-06-03T02:58:59+00:00

Here is my question: #data 1: lab1 <- 1:10 group <- rep(1:3, each =

  • 0

Here is my question:

#data 1:
lab1 <- 1:10
group <- rep(1:3, each = length (lab1))
label <- rep(lab1, 3)
avar <-  rep(c(0, 1, 4, 5, 6, 8, 10,  11, 12,  13), 3)
myd <- data.frame (group, label, avar)

# data 2
fillcol <- rep(rnorm(length(lab1)-1, 0.5, 0.2), 3)
group1 <- rep(1:3, each = length(fillcol)/3)
 # this variable will be used to fill color in bars
 filld <- data.frame(group1, fillcol)

# now plotting
par(mfrow = c(3, 1))
 par(mar = c(2.5, 1, 2.5, 1))

#plot1
myd1 <- myd[myd$group ==1,]
filld1 <- filld[filld$group1 ==1,]
blues <- colorRampPalette(c("yellow", "blue"))
barplot(as.matrix(diff(myd1$avar)), horiz=T, col=blues(10)[10* filld1$fillcol], 
 axes=F, xlab="Mark")
axis(1, labels=myd$label, at=myd$avar)
axis(3, labels=myd$avar, at=myd$avar)

Although this sample dataset, I have many variables and I want to automate this process.

for (i in 1:length(unique(myd$group))){
         par(mfrow = c(i, 1))
        par(mar = c(2.5, 1, 2.5, 1))
                myd[i] <- myd[myd$group ==i,]
        filld[i] <- filld[filld$group1 ==i,]
      blues <- colorRampPalette(c("yellow", "blue"))
      barplot(as.matrix(diff(myd[i]$avar)), horiz=T, 
   col=blues(10)[10* filld1$fillcol], axes=F, xlab="Mark")
      axis(1, labels=myd[i]$label, at=myd[i]$avar)
        axis(3, labels=myd[i]$avar, at=myd[i]$avar)
        }
 Error in dim(data) <- dim : attempt to set an attribute on NULL
In addition: Warning messages:
1: In `[<-.data.frame`(`*tmp*`, i, value = list(group = c(1L, 1L, 1L,  :
  provided 3 variables to replace 1 variables
2: In `[<-.data.frame`(`*tmp*`, i, value = list(group1 = c(1L, 1L,  :
  provided 2 variables to replace 1 variables

Edits: I want to create a loop so that I create multiple graphs within the loop:

enter image description here

PS: I am new to R and stackoverflow. Please excuse me if the question is not appropriate, although I read the guidelines and try to adhere to it

  • 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-03T02:59:01+00:00Added an answer on June 3, 2026 at 2:59 am

    If you wrap it in a function like this, you should be able to get it to work and be called multiple times.

    colbarplot <- function(group) {
    
        myd1 <- myd[myd$group == group,]
        filld1 <- filld[filld$group1 == group,]
        blues <- colorRampPalette(c("yellow", "blue"))
        barplot(as.matrix(diff(myd1$avar)), horiz=T,
                col=blues(10)[10* filld1$fillcol], 
                axes=F, xlab="Mark")
        axis(1, labels=myd$label, at=myd$avar)
        axis(3, labels=myd$avar, at=myd$avar)
    }
    
    par(mfrow = c(3, 1))
    par(mar = c(2.5, 1, 2.5, 1))
    sapply(unique(myd$group),function(x) colbarplot(x))
    

    This will give the multiple plots on one page you are after.

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

Sidebar

Related Questions

Another stupid question here regarding a SQL scenario. Given data such as: FieldKey DocumentKey
I have a silly question here. I define a class with many data members,
Possible Duplicate: How to append data to a file? Quick question here, how can
I asked a question a while back on here regarding caching data for a
SSRS newbie question here... I have a table where one column is varbinary(max) data.
Quick question about data joining. Say I have some elements that each contain a
Newbie question here. I'd like to be able to specify through data (i.e. an
a newbie question here... I've created an entity data model (.edmx) file in one
I have already asked a similar question here: Python open raw audio data file
got a few question here. i just want to get the data from the

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.