Wednesday, November 30

Data Visualization : Jump Start Plotting With R

Why is data visualization important?

Data Visualization is important because of the way the human brain processes information, using charts or graphs to visualize large amounts of complex data is easier than poring over spreadsheets or reports. Data visualization is a quick, easy way to convey concepts in a universal manner – and you can experiment with different scenarios by making slight adjustments.

Preparing your organization for data visualization technology requires that you first:

  • Understand the data you’re trying to visualize, including its size and cardinality (the uniqueness of data values in a column).
  • Determine what you’re trying to visualize and what kind of information you want to communicate.
  • Know your audience and understand how it processes visual information.
  • Use a visual that conveys the information in the best and simplest form for your audience.
 Here are some simple ways to plot data using R tools.


     
  1. Basic scatterplot - Main arguments x and y are vectors indicating 
    the x and y coordinates of the data points (in this case, 10).
    Code-
    plot(x = 1:10,
         y = 1:10,
         xlab = "My-XAxis",
         ylab = "My=YAxis",
         main = "Graph Title")
     
     
  2. Using Transparent Colors in plots - Example of basic plotting with color using "yarrr" package transparent color - Most plotting functions have a color argument
     (usually col) that allows you to specify the color of whatever your plotting.
    Code-
    plot(x = pirates$height, 
         y = pirates$weight, 
         col = yarrr::transparent("blue", trans.val = .9), 
         pch = 16, 
         main = "col = yarrr::transparent('blue', .9)") 
  3. Using default R Colors in plots - Most plotting functions have a color argument
     (usually col) that allows you to specify the color of whatever your plotting.
    Code
    plot(x = pirates$height, 
         y = pirates$weight, 
         col = "blue", 
         pch = 16, 
         main = "col ='blue'")
     
     
  4. Plotting scatterplot with arguments - Example of plotting with arguments. he plot() function makes a scatterplot from two vectors x 
    and y, where the x vector indicates the x (horizontal) values of the 
    points, and the y vector indicates the y (vertical) values. 
    Code
    plot(x = 1:10,                         # x-coordinates
         y = 1:10,                         # y-coordinates
         type = "p",                       # Just draw points (no lines)
         main = "My First Plot",
         xlab = "This is the x-axis label",
         ylab = "This is the y-axis label",
         xlim = c(0, 11),                  # Min and max values for x-axis
         ylim = c(0, 11),                  # Min and max values for y-axis
         col = "blue",                     # Color of the points
         pch = 16,                         # Type of symbol (16 means Filled circle)
         cex = 1)                           # Size of the symbols 
     
     
  5. Histograms are the most common way to plot a vector of numeric data.
    Code -
    hist(x = ChickWeight$weight,
         main = "Chicken Weights",
         xlab = "Weight",
         xlim = c(0, 500)) 
     
     
    
    
  6. Barplot typically shows summary statistics for different groups. 
    The primary argument to a barplot is height: a vector of numeric values which will generate the height of each bar.
    To add names below the bars, use the names.arg argument.  
    Code
    
    barplot(height = 1:5,  # A vector of heights
            names.arg = c("G1", "G2", "G3", "G4", "G5"), # A vector of names
            main = "Example Barplot", 
            xlab = "Group", 
            ylab = "Height")
     
     
  7. Pirateplot is a plot contained in the "yarrr package" written specifically by, and for R pirates The pirateplot is an easy-to-use function that, unlike barplots and boxplots, can easily show raw data, descriptive statistics, and inferential statistics in one plot.
     Code -


     yarrr::pirateplot(formula = weight ~ Time, # dv is weight, iv is Diet
                   data = ChickWeight,
                   main = "Pirateplot of chicken weights",
                   xlab = "Diet",
                   ylab = "Weight")
 

Finally, we can save these graphs as pdf file using pdf function of R
Code pdf(file = "D:\MyPlot.pdf",   # The directory you want to save the file in
    width = 4, # The width of the plot in inches
    height = 4) # The height of the plot in inches

# Step 2: Create the plot with R code
plot(x = 1:10,
     y = 1:10)
abline(v = 0) # Additional low-level plotting commands
text(x = 0, y = 1, labels = "Random text")

# Step 3: Run dev.off() to create the file!
dev.off()

  

No comments:

Post a Comment

MUSTREAD : How can you use Index Funds to help create wealth? HDFC MF Weekend Bytes

https://www.hdfcfund.com/knowledge-stack/mf-vault/weekend-bytes/how-can-you-use-index-funds-help-create-wealth?utm_source=Netcore&...