0
votes

I am starting to learn R programming for my thesis. I was just trying to plot some data, to see if I could find any threshold or pattern, and I used the ggplot() function. However, the axis appears and the data didn't. Like is shown in the picture bellow

I tried two ways of printing the plot and none of them worked.

Is there anything that you can help me with?

And I am sorry if this is a really stupid question, but I am really beginning and I really need this. Thank you a lot


title: "RNN-LSTM-tutorial" output: html_document: df_print: default editor_options:

chunk_output_type: inline


download.file("https://s3.amazonaws.com/keras-datasets/jena_climate_2009_2016.csv.zip","~/R/RNNTutorial/jena_climate_2009_2016.csv.zip")
unzip("~/R/RNNTutorial/jena_climate_2009_2016.csv.zip", "..."

library(tibble)
library(readr)
library(ggplot2)
library(keras)
library(tensorflow)


data_dir <- "~/R/RNNTutorial"
fname <- file.path(data_dir, "jena_climate_2009_2016.csv")
raw_data <- read.csv(fname)


p <- ggplot(raw_data, aes(x = 1:nrow(raw_data), y = 'T (degC)'))
p <- p + geom_line()
print(p)

ggplot(raw_data[1:1000, ], aes(x = 1:1000, y = 'T (degC)')) + geom_line()

GGPlot Image - Graph 1

GGPlot Image - Graph 2

1

1 Answers

1
votes

I think this is related to having a string 'T (degC)' as y in your ggplot statement. You'll notice if you change this string (bounded by single quote) to anything, you'll get the same plot. It's not pulling data from a column, but just treating the character string as a single discrete value.

Instead, you need the actual column name, which appears to be: T..degC. (original names may have had spaces in them).

To check the column names:

names(raw_data)
 [1] "Date.Time"       "p..mbar."        "T..degC."        "Tpot..K."        "Tdew..degC."     "rh...."          "VPmax..mbar."   
 [8] "VPact..mbar."    "VPdef..mbar."    "sh..g.kg."       "H2OC..mmol.mol." "rho..g.m..3."    "wv..m.s."        "max..wv..m.s."  
[15] "wd..deg."

This should work:

ggplot(raw_data, aes(1:nrow(raw_data), T..degC.)) +
  geom_line()

Plot

plot with column name included as y