Thursday 15 September 2011

plot - What's wrong with my code? Histograms in R with percentage as .png -


Stack Overflow has already helped me a lot, but I have difficulty in uniting everything.

I create a histogram with data stored in automatic Txt files Each file has a data column.

I wrote this and it works, the original code is:

  #! / Usr / bin / env Rscript # All directories for a .txt file (i in 1: length (list.files (pattern = "*. Txt"))) {#reading data histo = read.table (list .files (pattern = "* .txt") [i]) #cutting off ".txt" name = list.files (pattern = "* .txt") [i] name = strsplit (name, ".", Fixed = TRUE) Name [name] [1] png (name) hist (main = paste ("histogram de proxy", name), histo $ v1, break = 10, freak = falls, #looks col = " Gray ", tck = -0.015, #labels xlab =" srednica [Um] ", ylab =" gestosc ") box () dev.off ()}  

It looks like this:

I want to change the y axis and the label for each column that I have changed my code, which I found on SO and other sites, implemented it, I corrected any errors when I run the script so it's a The error does not return and it seems that it works. However, it does not produce any images.

The new code looks like this:

  #! / Usr / bin / env for rupcript (1 in length: (list.files (pattern = "* .txt"))) {#reading data histo = read.table (list.files (pattern = "* .txt "[Name]" = "[.txt"] [i] name = strsplit (name, ".", Fixed = TRUE) [[1]] name = name [1] #cutting ".txt" Histpresent & lt; - Function (histo) {PNG (name) H & L; - Hist (Histo $ V1, Plot = Fles) H $ density & lt; - Together (H, 100 * density * difference (brake) [1]) Labs & lt; - Paste (round (H $ density), "%", sep = "" plot (h, main = paste (name "histogram del prokie", name), histo $ v1, break = 10, freak = flays, #looks col = "Green", tck = -0.015, labels = labs, xlab = "średnica [um]", ylab = "udział procentowy") dev.off ()} #box ()}  
< P> What's wrong? I also tried with png () and dev.off () outside of the function.

Your function histpaint is not kept properly, so you can not find any output. Shout ...

R Code:

  #! / Usr / bin / env Rscript # for all .txt files A directory (i in 1: length (list.files (pattern = "*. Txt")) {#reading data histo = read.table (list.files (pattern = "*. Txt") [i]) # Cutting off ".txt" name = list.files (pattern = "* .txt") [i] name = strsplit (name, ".", Fixed = TRUE) [[1]] name = name [1] png Name) H = Hist (Histo $ V1) H $ density = Calculation of H $ / zodiac (H dollar calculation) * 100 laboratories & lt; - Plot (H $ Density), "%", sep = "") Plot (H, Main = Paste ("Histogram Del Prokie", name), Freak = F, Label = Labs, Histo $ V1, Break = 10, col = "lightgreen", tck = -0.015, xlab = "srednica [um]", output:  

Hope this will be helpful.


No comments:

Post a Comment