How to change x-label in plot without showing the previous values?

Rollo99

I'm tryng to plot with plot the following:

df = (DF = c(24, 62, 37, 27, 50, 20, 23, 23, 25, 20, 27, 25, 24, 11, 23, 21, 17, 20, 17, 13, 13, 13, 15, 15, 14, 10))

plot(df$DF, type = "o", col = "red", lwd = 2, xlab = "", ylab = "Growth Rate (%)") 

The problem is that I get on the x-axis numbers from 1 to 27.

I would like to have days there from Feb 25 to March 22. So, I tried:

df$Date <- seq(as.Date("2020/02/25"), as.Date("2020/03/22"), by = "days")

plot(df$DF, type = "o", col = "red", lwd = 2, xlab = "", ylab = "Growth Rate (%)") + axis(1, at=1:27, labels= df$Date, cex.axis=0.5)

The problem is that the new x-label is written on the old one.

How can I fix it?

Thanks

Leonardo Donato Nunes
# Create the data
df = data.frame(DF = c(24, 62, 37, 27, 50, 20, 23, 23, 25, 20, 27, 25, 24, 11, 23, 21, 17, 20, 17, 13, 13, 13, 15, 15, 14, 10))

df$Date <- seq(as.Date("2020/02/25"), as.Date("2020/03/21"), by = "day")
df$data_line <- c(24, 62, 37, 27, 50, 20, 23, 23, 25, 20, 27, 25, 24, 11, 23, 21, 17, 20, 17, 13, 13, 13, 15, 15, 14, 10) + 2

# Open the plot area 
     plot(df$Date, df$DF, 
     type = "o", col = "red", lwd = 2, xlab = "",ylab = "Growth Rate (%)", axes = F)

     # Configuring the new axes
     axis.Date(1, at = seq(min(df$Date), max(df$Date), by ="day"), cex.axis= 0.5)
     axis(2, las = 2)

     # Add a new line     
     lines(df$Date, df$data_line, col = "blue")

     # Close the box around the plot area
     box()             

Hi Rollo,

In base r plot, I prefer to insert each thing separately. I recreated your data example and plot the data again. I plotted a blue line with a new example of data, created by adding 2 to the original DF data, it was stored in df$data_line.

When I called the plot, I used the argument 'axes = F', to omit the original axes. After this I called the two axes, with different functions.

In r base plot you can't use "+" between functions when you open a plot.

Hope my code helps you!

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

how to change axes values for a plot in r

分類Dev

How to plot only the last x values of a result?

分類Dev

How to set and display x/y label with pandas plot in ipython notebook?

分類Dev

The x label of a box plot is shifted

分類Dev

How to change the order of categorical values on y axis of a plot

分類Dev

Layered or Facet bar plot with label values in Altair

分類Dev

Change label of cell values but keep their colouring

分類Dev

r - how to add label in corner of polar plot

分類Dev

Matplotlib: how to set a tick label above a plot

分類Dev

How to plot errorbars on this plot and change the overlay?

分類Dev

How to change label of cytoscape nodes

分類Dev

Change plot label when plotting different dataframes in pandas

分類Dev

How to plot a scatter plot using a pandas dataframe where the x-axis values are n minus 1 columns and the last column is the dependent variable?

分類Dev

How to change Scale in raster plot?

分類Dev

How to plot values by row in pheatmap?

分類Dev

Does python lists in recursion do not change to its previous values?

分類Dev

How to change the label of back button in Ionic 4?

分類Dev

How I can create a dynamically label change?

分類Dev

How to change label length on AS3 checkbox?

分類Dev

label change text every x seconds c# array

分類Dev

How to plot individual points without curve in python?

分類Dev

How to change Pandas plot annotation to whole number?

分類Dev

How to plot values by specific column for a comparison

分類Dev

change x location of violin plot in ggplot2

分類Dev

cannot change the main title and x, y labels for plot() of boot() result

分類Dev

How to plot horizontal lines with text (i.e. a label) on a polar coordinates matplotlib plot? (Python)

分類Dev

How to plot a dataframe using date as the x axis

分類Dev

Hiding xticks labels every n-th label or on value on Pandas plot / make x-axis readable

分類Dev

Caculate groups' multiple current values based on pct_change and previous values in Pandas

Related 関連記事

  1. 1

    how to change axes values for a plot in r

  2. 2

    How to plot only the last x values of a result?

  3. 3

    How to set and display x/y label with pandas plot in ipython notebook?

  4. 4

    The x label of a box plot is shifted

  5. 5

    How to change the order of categorical values on y axis of a plot

  6. 6

    Layered or Facet bar plot with label values in Altair

  7. 7

    Change label of cell values but keep their colouring

  8. 8

    r - how to add label in corner of polar plot

  9. 9

    Matplotlib: how to set a tick label above a plot

  10. 10

    How to plot errorbars on this plot and change the overlay?

  11. 11

    How to change label of cytoscape nodes

  12. 12

    Change plot label when plotting different dataframes in pandas

  13. 13

    How to plot a scatter plot using a pandas dataframe where the x-axis values are n minus 1 columns and the last column is the dependent variable?

  14. 14

    How to change Scale in raster plot?

  15. 15

    How to plot values by row in pheatmap?

  16. 16

    Does python lists in recursion do not change to its previous values?

  17. 17

    How to change the label of back button in Ionic 4?

  18. 18

    How I can create a dynamically label change?

  19. 19

    How to change label length on AS3 checkbox?

  20. 20

    label change text every x seconds c# array

  21. 21

    How to plot individual points without curve in python?

  22. 22

    How to change Pandas plot annotation to whole number?

  23. 23

    How to plot values by specific column for a comparison

  24. 24

    change x location of violin plot in ggplot2

  25. 25

    cannot change the main title and x, y labels for plot() of boot() result

  26. 26

    How to plot horizontal lines with text (i.e. a label) on a polar coordinates matplotlib plot? (Python)

  27. 27

    How to plot a dataframe using date as the x axis

  28. 28

    Hiding xticks labels every n-th label or on value on Pandas plot / make x-axis readable

  29. 29

    Caculate groups' multiple current values based on pct_change and previous values in Pandas

ホットタグ

アーカイブ