您可以指定數據的一個子集 - 即你所期望的2分geom_point
,這裏我用C(25,50)
使用geom_segment
創建虛線的子集化的點
使用scale_x_continuous
和scale_y_continuous
創建軸標籤
使用theme
改變劇情的主題元素
# Create geom_point and geom_segments
gg1 <- ggplot(data, aes(x, y)) + geom_line(lwd=2) +
geom_point(data=data[data$x %in% c(25, 50),], aes(x, y), pch=16, size=5) +
geom_segment(data=data[data$x %in% c(25, 50),], aes(x=x, xend=x, y=0, yend=y), lty=2, lwd=1) +
geom_segment(data=data[data$x %in% c(25, 50),], aes(x=0, xend=x, y=y, yend=y), lty=2, lwd=1)
gg1
# Define new labels
x_label <- NA
x_label[! x %in% c(25, 50)] <- ""
x_label[x %in% c(25, 50)] <- c("Q", "Q1")
y_label <- NA
y_label[! x %in% c(25, 50)] <- ""
y_label[x %in% c(25, 50)] <- c("NIR", "NIR1")
gg2 <- gg1 + scale_x_continuous(breaks=x, labels=x_label) +
scale_y_continuous(breaks=y, labels=y_label)
gg2
# Add axis labels, change theme elements, remove ticks and grid lines
gg3 <- gg2 + xlab("Quantity of Investment") +
ylab("Norminal Interest Rate") +
theme_bw() +
theme(panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
axis.ticks = element_blank(),
axis.title = element_text(size=16),
axis.text = element_text(size=14))
gg3
請提供樣本數據。請參閱[這裏](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example)以供參考。 – www
這些圖的數據我通常只是補充,因爲它不是關於數據,只是直覺 – MightyMauz
所以說 x < - c(10:100),y < - 1/x,data < - data.frame(x, y),ggplot(data,aes(x,y))+ geom_line() – MightyMauz