Hi,
Try:
 lines1 <- readLines("Garbage.txt",warn=FALSE)
dat1 <- 
read.table(text=gsub("\t+","\t",lines1),stringsAsFactors=FALSE,sep="\t",check.names=FALSE,header=TRUE)
 str(dat1)
#'data.frame':    10 obs. of  3 variables:
# $ Material            : chr  "Food Scraps" "Glass" "Metals" "Paper" ...
# $ Weight(Million Tons): num  25.9 12.8 18 86.7 24.7 ...
# $ Percent             : num  11.2 5.5 7.8 37.4 10.7 6.8 5.5 11.9 3.2 100
jpeg("garbageweight.jpg",width=800)
 
barplot(dat1[-10,2],names.arg=dat1[-10,1],ylab=colnames(dat1)[2],col=rainbow(9),main="American
 garbage")
 dev.off()


A.K.


Hello guys, I'm having this weird problem with my assignment. I can't seem to 
import the data that I have created. 

I keep getting an error that says "Error: More Columns than Column names" 

This is my data file. 
Garbage.txt

Was also wondering if you guys could send me into the right direction on how to 
do this. 

1. Create a data frame with the data given above. 
2. Create the bar plot for weight variable with appropriate labels. Resize the 
graphics 
panel/ window so that all labels are visible. 
3. Add colors. Suppose n is the number of bars. 
> barplot(..., col = rainbow(n)) 
4. Save the plot to garbageweight.jpg 

This is how it's supposed to look like at the end.

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to