我試圖擺脫geom_label在輸出爲pdf時創建的邊框。設置lable.size = 0
似乎在輸出到png時或在R會話中的繪圖窗口中工作,但當輸出爲pdf時,邊界仍然存在。我喜歡geom_text上的geom_label,因爲背景使得在劇情中有線條時易於閱讀。由於我對後面的情節做了些什麼,所以如果有人知道如何擺脫邊界將會很棒,那麼我可以更容易地獲得pdf輸出。在R輸出爲ggplot2 geom_label的PDF輸出中刪除邊框
我目前在Mac OS Sierra上使用ggplot 2.2.1和R 3.3.3。以下是一些示例代碼。
require(ggplot2)
#no border
ggplot(data.frame(nums = 1:10), aes(x =nums, y = nums)) +
geom_point() +
geom_label(label = "italic(R)^2 == .87", label.size = 0, x = 2, y = 8, vjust = "inward", hjust = "inward", parse = T) +
theme_bw()
pdf("testPlot.pdf")
#border appears in pdf
print(ggplot(data.frame(nums = 1:10), aes(x =nums, y = nums)) +
geom_point() +
geom_label(label = "italic(R)^2 == .87", label.size = 0, x = 2, y = 8, vjust = "inward", hjust = "inward", parse = T) +
theme_bw())
dev.off()
png("testPlot.png")
#no border with png
print(ggplot(data.frame(nums = 1:10), aes(x =nums, y = nums)) +
geom_point() +
geom_label(label = "italic(R)^2 == .87", label.size = 0, x = 2, y = 8, vjust = "inward", hjust = "inward", parse = T) +
theme_bw())
dev.off()
嗯,當我做R環境中的情節和PNG文件都有一個圍繞它們的框。我認爲這是'ggplot'不能讓你指定0的問題。一個解決方法(雖然它提供了很多警告消息)正在使用'label.size = unit(0,「mm」)'。 –