logo
down
shadow

why does the data I input into R plot function change?


why does the data I input into R plot function change?

By : Aniket
Date : October 18 2020, 06:10 AM
it should still fix some issue Please provide a reproducible example with the actual data. That really helps you to get help. From your examples, I think you need to understand the type of variables you are working with. In this case, differences between character and numeric variables and factors matter.
I can reproduce your plots with the following code where the values you posted are copied and then entered with the scan function. Your data have been placed in a data frame.
code :
Years <- scan() # copy and paste 'years' data
Deaths <- scan(what = "", sep = " ") # copy and paste 'totals' (deaths)
df <- data.frame(Years, Deaths)
opar <- par(mfrow = c(1, 2))
main <- "Deaths Over the Years"
plot(Years ~ Deaths, df, main = main, ylab = "Deaths", xlab = "Years")
plot(as.numeric(Deaths) ~ Years, df, type = "l", main = main, ylab = "Deaths")
par(opar)
Deaths2 <- as.numeric(gsub(",", "", Deaths))
df$Deaths2 <- Deaths2 # add this variable to the data frame
plot(Deaths2 ~ Years, df, type = "l", main = main, ylab = "Deaths")


Share : facebook icon twitter icon
I found ways to plot a graph in R using plot function. but I am looking to create plot with part of the data

I found ways to plot a graph in R using plot function. but I am looking to create plot with part of the data


By : Alex
Date : March 29 2020, 07:55 AM
This might help you I am trying to plot a graph for a data containing years between 1900 and 2010 and output in each month of the year in R. I need to select years between 1950-2001 against months of Nov-february. How can I select part of data for plotting this graph ? since I am a rookie at R programming or any programming, an easy to follow example would be of great help. , I am not sure exactly what you mean by
code :
#create a vector of months from 1900 through 2010
months <- seq(as.Date("1900/1/1"), as.Date("2010/12/31"), "months")
#assign a random vector of equal length
output <- rnorm(length(months))
#assign both values to a data_frame
data <- data.frame(months = months, output = output)
#subset to just 1950 through 2001
data_sub <- subset(data, months >= as.Date("1950-01-01") & months <= as.Date("2001-12-31"))
#subset the 1950 to 2001 data to just Nov-feb months (i.e. c(11,12,1,2))
data_sub_nf <- subset(data_sub, as.numeric(format(data_sub$months, "%m")) %in% c(11,12,1,2))
Can't change type of plot in plot() for data.frame (that is not only numeric) in R

Can't change type of plot in plot() for data.frame (that is not only numeric) in R


By : Francisco Santillan
Date : March 29 2020, 07:55 AM
will be helpful for those in need Expanding upon @alexis_laz's comment, you could hack your way out of this by initializing an invisible boxplot and consequently plotting your data on it.
code :
 # set border argument of boxplot() to "white"
 plot(a, border = "white")

 # add points to your plot
 points(a$col2 ~ a$col1, col = "blue", type= "o")
How to input both wind speed and direction data and pcolormesh plot it in python, with both on the same plot?

How to input both wind speed and direction data and pcolormesh plot it in python, with both on the same plot?


By : Remelyn Palacsa Cali
Date : March 29 2020, 07:55 AM
wish helps you I have some wind speed and direction data that I need to plot into python. I got the data from a data file and did some calculations to get the wind speed and data, and here is what I got: , How about:
code :
import matplotlib.pyplot as pl
pl.pcolormesh(wind_dir_cardinal)
How do I use animation in shiny in R to change data on plot without redrawing plot itself?

How do I use animation in shiny in R to change data on plot without redrawing plot itself?


By : nikhar
Date : March 29 2020, 07:55 AM
like below fixes the issue No, you can't.
Very long answer: Plots are rendered as png (see ?plotPNG) before they're inserted in the web interface. So if you change something on the plot, you can't but rerender the entire image to be shown.
How can one initialize data for a contour plot using a function that takes one input and outputs a scalar value?

How can one initialize data for a contour plot using a function that takes one input and outputs a scalar value?


By : Kieran
Date : March 29 2020, 07:55 AM
like below fixes the issue If I understood your idea correctly then this should be what you need. However I needed the following packages:
code :
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
from matplotlib.mlab import griddata
import pandas as pd
lower_bounds = [];
upper_bounds = [];
z_values = [];
for j in range(1, 30):
  for i in range(0,j):
    mod_dictionary = subsect(data_dictionary, indices=slice(i, j, 1))
    lower_bounds.append(mod_dictionary['datetime'][0])
    upper_bounds.append(mod_dictionary['datetime'][-1])
    z_values.append(get_z(mod_dictionary))
lower_bounds_dt = [pd.Timestamp(date).value for date in lower_bounds]
upper_bounds_dt = [pd.Timestamp(date).value for date in upper_bounds]
xi = np.linspace(min(lower_bounds_dt), max(lower_bounds_dt), 100)
print(xi)
yi = np.linspace(min(upper_bounds_dt), max(upper_bounds_dt), 100)
print(yi)
zi = griddata(lower_bounds_dt, upper_bounds_dt, z_values, xi, yi)
print(zi)
fig1 = plt.figure(figsize=(10, 8))
ax1 = fig1.add_subplot(111)
ax1.contourf(xi, yi, zi)
fig1.savefig('graph.png')
Related Posts Related Posts :
  • convert numbers written in words to numbers using R programming
  • In R, how can I look up a value in one column based on an interval in adjoining columns that includes values I want to m
  • Convert Date in YYYYMM to YYYY-MM-DD
  • grep does not show all the indices, only [1]1
  • Normalizing a dataframe having several conditions, R
  • What is the equivalent of "everything()" operator in "data.table"?
  • The colors in ggplot do not correspond to the colors in the legend
  • How to add to each column of dataframe value from named vector?
  • Losing data while saving csv character file
  • How to target arbitrary HTML attribute containing space in R?
  • Iterate over a column and find the sum
  • reference another column with tidyeval in filter
  • How to create a new variable by comparing two other variables
  • Retrieving elements that are occurring after adding a fixed number from a start element in a vector
  • Get total mean for variables nested in a list of lists of lists
  • Render Xaringan Rmd when using _site.yml file
  • Regex: matching multiple patterns and getting middle of string
  • removing for loop with sample function
  • R: scraping additional data after POST only works for first page
  • R - Add ticks on top of plot with levels in variable?
  • How to avoid factors in R when reading csv data
  • Meaning of :: syntax
  • How to get month and week of the month from year and week no in R?
  • Can you save R code files with .RData objects for version control?
  • How to connect points of two different plots to each other using ggplot in R?
  • Is there an R function for finding the value below specific value
  • R group_by return number of largest unique type
  • Different ways of selecting columns inside function resulting in different results, why?
  • How do I join a Y variable to each X variable in a dataframe?
  • World map: filtering by 'subregion' removes many regions
  • Generate data frame with parameters
  • Star (*) notation in R session Information
  • Why does formals function return NULL on functions defined with arguments?
  • How to call a list style parameter in snakemake
  • as_tibble only returns a single variable
  • Can't create design matrix from user input
  • R - how to sum each columns from df
  • R devtools::check LICENSE is not mentioned and other issues in DESCRIPTION FILE
  • Simple arithmetic leads to floating point difference in R
  • How can I import my data.frame as an igraph object?
  • Join each row with each other row
  • Join complementary dataframes, no NAs where a value is available
  • How to restart R and continue a benchmark script from previous line (on Windows)?
  • using dplyr to calculate consecutive days with a particular value
  • When and how to use as.name() vs.get() in data.table (ex. in looping over columns)?
  • How to combine similar strings showing most common characters
  • Adjust spacing between text and chunk output in a R Markdown PDF document
  • Transform data to use lubridate on it
  • I need to know why I get the error 'unexpected input in "p<-ggplot(data=mov2, aes(x=Genre,y=Gross % US))" '
  • ggplot different lm formulas
  • change border color of a county in ggplot in R
  • position_dodgev causes error in order of connecting points in geom_line
  • How can I delete lines in which the name appears only once?
  • mutate_if, summarize_at etc coerce data.table to data.frame
  • How to get different values for same ID in dataframe. And replace any of that different value for the same ID
  • Lagging data based on condition (non-fix lag)
  • How to use 'sparklyr::replace.na()' for replacing NaN on one column?
  • How to create lollipop graph
  • R: Why is pmap not working while map2 does?
  • How to have different legends and colour schemes for different geom_*(aes(col= ) in ggplot?
  • shadow
    Privacy Policy - Terms - Contact Us © 35dp-dentalpractice.co.uk