johnmyleswhite / ML_for_Hackers

Code accompanying the book "Machine Learning for Hackers"
http://shop.oreilly.com/product/0636920018483.do
3.67k stars 2.22k forks source link

Chapter 3 motivating plot #50

Open jamessv opened 7 years ago

jamessv commented 7 years ago

`> spam.path <- file.path("C:\03-Classification\data", "spam")

spam2.path <- file.path("C:\03-Classification\data", "spam_2") easyham.path <- file.path("C:\03-Classification\data", "easy_ham") easyham2.path <- file.path("C:\03-Classification\data", "easy_ham_2") hardham.path <- file.path("C:\03-Classification\data", "hard_ham") hardham2.path <- file.path("C:\03-Classification\data", "hard_ham_2") x <- runif(1000, 0, 40) y1 <- cbind(runif(100, 0, 10), 1) y2 <- cbind(runif(800, 10, 30), 2) y3 <- cbind(runif(100, 30, 40), 1) val <- data.frame(cbind(x, rbind(y1, y2, y3)),

  • stringsAsFactors = TRUE) ex1 <- ggplot(val, aes(x, V2)) +
  • geom_jitter(aes(shape = as.factor(V3)),
  • position = position_jitter(height = 2)) +
  • scale_shape_discrete(guide = "none", solid = FALSE) +
  • geom_hline(aes(yintercept = c(10,30)), linetype = 2) +
  • theme_bw() +
  • xlab("X") +
  • ylab("Y") ggsave(plot = ex1,
  • filename = file.path("C:\03-Classification\images", "00_Ex1.pdf"),
  • height = 10,
  • width = 10) Error in grDevices::pdf(..., version = version) : cannot open file 'C:\03-Classification\images/00_Ex1.pdf'

ggsave(plot = ex1,

getwd() [1] "C:/Users/mm/Documents"

`

hao2leaf commented 5 years ago

You can split "geom_hline(aes(yintercept = c(10,30)), linetype = 2) +" into "geom_hline(aes(yintercept = c(10)), linetype = 2) + geom_hline(aes(yintercept = c(30)), linetype = 2) +". This will help.