0

I'm new to R programming can someone help with fix this problem,

for both scatterplot and histogram my class column has only 1,0 values but get output on my plot as 0.1,0.2...1.0

scatterplot

options(scipen = 999)

pdf("visualization.pdf")
# install.packages("scales")
# Scatter plot

library(tidyverse)
dataset <- read.csv("creditcard.csv")
amount <- dataset$Amount
class <- dataset$Class
plot(amount, class,
     main = "correlation between the amount of transaction and\n
     the occurrence of credit card fraud",
     xlab = "Amount", ylab = "Class",
     ylim = c(0, 3),
     pch = 19, frame = T
)
m <- lm(class ~ amount, data = dataset)
abline(m, col = "green")

# histogram

h <- hist(class,
     6,
     main = "",
     xlim = c(0, 3),
     ylab = "Amount",
     xlab = "Class",
     col = "red"
)
amount <- seq(min(class), max(class), 1)
Mn <- mean(class)
StdD <- sd(class)
y1 <- dnorm(amount, mean = Mn, sd = StdD)
y1 <- y1 * diff(h$mid[1:2] * length(class))
lines(amount, y1, col = "blue")

dev.off()

On my y-axis I only need to show 0 and 1, I tried using

scale_y_continuous(breaks= pretty_breaks())

but haven't solved my problem as it was giving errors

cookie s
  • 65
  • 1
  • 6
  • 2
    `scale_y_continuous` is for ggplot, so it won't have any effect on base `plot` calls – camille Dec 09 '22 at 19:50
  • 1
    For base graphics, you can set `axis = FALSE` in the plot command and then use the `axis()` function separately to draw axes as you like. Which is kind of a pain... most people prefer `ggplot` these days. – Gregor Thomas Dec 09 '22 at 19:54

0 Answers0