The first scholarly work on toilet graffiti was very likely The Merry-Thought: or the Glass-Window and Bog-House Miscellany. Part 1 written and published by ‘Hurlo Thrumbo’ in 1731.
‘Hurlo Thrumbo’ was, many believe, none other than poet, playwright, essayist, moralist, literary critic, biographer, editor, lexicographer. and man-of-letters Samuel Johnson himself.
“The Original Manuscripts written in Diamond* by Persons of the first Rank and Figure in Great Britain; relating to Love, Matrimony, Drunkenness, Sobriety, Ranting, Scandal, Politicks, Gaming, and many other Subjects, Serious and Comical.
Faithfully Transcribed from the Drinking-Glasses and Windows in the several noted Taverns, Inns, and other Publick Places in this Nation. Amongst which are intermixed the Lucubrations of the polite Part of the World, written upon Walls in Bog-houses, &c.”
Since then, there have been several more scholarly studies of toilet graffiti. See for example, a 2007 work from the Centre for the Study of Language in Social Life, Department of Linguistics and English Language, Bowland College, Lancaster University, UK, entitled : ‘Dialogues in solitude: the discursive structures and social functions of male toilet graffiti’ (Working Paper No. 126)
“The genre is seen as hybrid, incorporating both spoken and written features, and as located in three contexts: the micro-context of the physical location, the mesocontext of social relations at the institution and the macro-context of the wider social formation.”
 The full 2007 paper is available here, but unlike Hurlo Thrumbo’s treatise, in which the gravitas of the lucubrations has largely been dampened by the mists of time, the new paper features many examples of foul language which current-day readers may well find grossly offensive.
 *The use of the word ‘diamond’ is literal rather than poetic – at the time, graffiti artists were in the habit of scratching their creations onto drinking glasses and glass windows using a cut diamond.